Example usage for com.itextpdf.text Paragraph add

List of usage examples for com.itextpdf.text Paragraph add

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph add.

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Creates and returns PDF input stream for the supplied string.
 * @param string to be printed in the PDF
 * @return PDF input stream.// w  w  w .  j  av  a 2 s.c o  m
 * @throws PhrescoException
 */
public static InputStream getStringAsPDF(String string) throws PhrescoException {
    if (isDebugEnabled) {
        S_LOGGER.debug("Entering Method DocumentUtil.getStringAsPDF(String string)");
    }
    try {
        com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PdfWriter.getInstance(docu, os);
        docu.open();
        Paragraph paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_LEFT);
        paragraph.setFirstLineIndent(MAGICNUMBER.INDENTLINE);
        paragraph.add("\n"); //$NON-NLS-1$
        paragraph.add(string);
        paragraph.add("\n\n"); //$NON-NLS-1$
        docu.add(paragraph);

        docu.close();

        //Create an inputstream to return.
        return new ByteArrayInputStream(os.toByteArray());
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }

}

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

private static void updateDoc(List<ArtifactGroup> modules, com.itextpdf.text.Document docu, PdfWriter writer,
        String moduleName) throws PhrescoException {
    try {/*from  w w  w  .j  a  va2 s .  c  o  m*/
        Paragraph para = new Paragraph();
        para.setAlignment(Element.ALIGN_CENTER);
        para.setFont(DocConstants.BODY_FONT);
        para.setFont(DocConstants.CATEGORY_FONT);
        para.add(moduleName);
        addBlankLines(para, MAGICNUMBER.BLANKLINESTWO);
        docu.add(para);

        for (ArtifactGroup artifactGroup : modules) {
            para = new Paragraph();
            para.setFont(DocConstants.CATEGORY_FONT);
            para.add(artifactGroup.getName());
            docu.add(para);

            if (StringUtils.isNotEmpty(artifactGroup.getDescription())) {
                para = new Paragraph();
                para.setFont(DocConstants.BODY_FONT);
                para.add(artifactGroup.getDescription());
                addBlankLines(para, 2);
                docu.add(para);
            }
            //          Documentation document = tupleBean.getDoc(DocumentationType.DESCRIPTION);
            //          if (document != null) {
            //              if(!StringUtils.isEmpty(document.getUrl())){
            //                  PdfInput convertToPdf = DocConvertor.convertToPdf(document.getUrl());
            //                  if(convertToPdf != null) {
            //                      DocumentUtil.addPages(convertToPdf.getInputStream(), writer, docu);
            //                  }
            //              } else {
            //                  para = new Paragraph();
            //                  para.setFont(DocConstants.BODY_FONT);
            //                  para.add(document.getContent());
            //                  addBlankLines(para, 2);
            //                  docu.add(para);
            //              }
            //          }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }
}

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Adds blank lines into the supplied paragraph.
 * @param p the Paragraph object// w  w w . j a v a  2s . co  m
 * @param noOfLines no of blank lines.
 */
private static void addBlankLines(Paragraph p, int noOfLines) {
    if (isDebugEnabled) {
        S_LOGGER.debug("Entering Method DocumentUtil.addBlankLines(Paragraph p, int noOfLines)");
    }
    if (isDebugEnabled) {
        S_LOGGER.debug("addBlankLines() No of Lines=" + noOfLines);
    }
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < noOfLines; i++) {
        sb.append("\n"); //$NON-NLS-1$
    }
    p.add(sb.toString());
}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Adds title section.//ww  w . ja v a 2 s.c  om
 * @param info the project info object
 * @return PDF input stream
 * @throws DocumentException
 */
public static InputStream getTitleSection(ProjectInfo info) throws DocumentException {
    if (isDebugEnabled) {
        S_LOGGER.debug(" Entering Method DocumentUtil.getTitleSection(ProjectInfo info)");
    }
    if (isDebugEnabled) {
        S_LOGGER.debug("getTitleSection() projectCode=" + info.getCode());
    }
    //create output stream
    com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PdfWriter.getInstance(docu, os);
    docu.open();

    //add standard title section with supplied info object
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setFont(DocConstants.TITLE_FONT);
    addBlankLines(paragraph, 10);
    paragraph.add(info.getName());
    addBlankLines(paragraph, 4);
    docu.add(paragraph);

    paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_CENTER);
    addBlankLines(paragraph, 10);
    String techName = info.getTechnology().getName();
    if (info.getTechnology().getVersions() != null) {
        paragraph.add(techName + " - " + info.getTechnology().getVersions().get(0));
    } else {
        paragraph.add(techName);
    }
    docu.add(paragraph);

    paragraph = new Paragraph();
    addBlankLines(paragraph, 10);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(DocumentMessages.getString("Documents.version.name") + getVersion(info)); //$NON-NLS-1$
    addBlankLines(paragraph, 7);
    docu.add(paragraph);
    paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    paragraph.setFont(DocConstants.DESC_FONT);
    paragraph.setFirstLineIndent(8);
    paragraph.add(info.getDescription());
    docu.add(paragraph);

    docu.close();

    //Create an inputstream to return.
    return new ByteArrayInputStream(os.toByteArray());

}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Creates and returns PDF input stream for the supplied string.
 * @param string to be printed in the PDF
 * @return PDF input stream./*from ww  w  .  jav a2  s.  c o  m*/
 * @throws DocumentException
 */
public static InputStream getStringAsPDF(String string) throws DocumentException {
    if (isDebugEnabled) {
        S_LOGGER.debug("Entering Method DocumentUtil.getStringAsPDF(String string)");
    }
    com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PdfWriter.getInstance(docu, os);
    docu.open();
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    paragraph.setFirstLineIndent(180);
    paragraph.add("\n"); //$NON-NLS-1$
    paragraph.add(string);
    paragraph.add("\n\n"); //$NON-NLS-1$
    docu.add(paragraph);

    docu.close();

    //Create an inputstream to return.
    return new ByteArrayInputStream(os.toByteArray());

}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

License:Apache License

private static void updateDoc(List<ModuleGroup> modules, com.itextpdf.text.Document docu, PdfWriter writer,
        String moduleName) throws DocumentException, PhrescoException, IOException {
    Paragraph para = new Paragraph();
    para.setAlignment(Element.ALIGN_CENTER);
    para.setFont(DocConstants.BODY_FONT);
    para.setFont(DocConstants.CATEGORY_FONT);
    para.add(moduleName);
    addBlankLines(para, 2);/*from  w  w  w  .ja  v  a  2 s .c om*/
    docu.add(para);

    for (ModuleGroup tupleBean : modules) {
        para = new Paragraph();
        para.setFont(DocConstants.CATEGORY_FONT);
        para.add(tupleBean.getName());
        docu.add(para);
        Documentation document = tupleBean.getDoc(DocumentationType.DESCRIPTION);
        if (document != null) {
            if (!StringUtils.isEmpty(document.getUrl())) {
                PdfInput convertToPdf = DocConvertor.convertToPdf(document.getUrl());
                if (convertToPdf != null) {
                    DocumentUtil.addPages(convertToPdf.getInputStream(), writer, docu);
                }
            } else {
                para = new Paragraph();
                para.setFont(DocConstants.BODY_FONT);
                para.add(document.getContent());
                addBlankLines(para, 2);
                docu.add(para);
            }
        }
    }
}

From source file:com.photoshop.misc.Factuurgenerator.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);//from  ww w.j  a va2s .com

    Image Logo = null;
    try {
        Logo = Image.getInstance(env.getProperty("logo") + "Photoshop_black.png");
        Logo.scaleAbsolute(200, 100);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
    }
    SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
    preface.add(Logo);
    Paragraph datum = new Paragraph(this.Getspringmessage("Date") + ": " + simpledatafo.format(new Date()),
            smallBold);
    datum.setAlignment(Element.ALIGN_RIGHT);
    preface.add(datum);
    Paragraph Factuurnummer = new Paragraph(this.Getspringmessage("invoicenumber") + ": " + order.getId(),
            smallBold);
    Factuurnummer.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Factuurnummer);
    addEmptyLine(preface, 1);

    //Aanmaken van de bedrijfs gegevens
    preface.add(new Paragraph(this.Getspringmessage("company"), subtitel));
    preface.add(new Paragraph("Rachelsmolen 1", subFont));
    preface.add(new Paragraph("5612MA Eindhoven", subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(this.Getspringmessage("accountNumber") + ": 165947888", subFont));
    preface.add(new Paragraph("Bank: Paypal", subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de bestellende persoons gegevens
    preface.add(new Paragraph(this.Getspringmessage("reciver") + ":", subtitel));
    preface.add(new Paragraph(order.getInvoiceaddress().getKlantnaam(), subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(order.getInvoiceaddress().getAdres(), subFont));
    preface.add(new Paragraph(
            order.getInvoiceaddress().getPostcode() + " " + order.getInvoiceaddress().getWoonplaats(),
            subFont));
    preface.add(new Paragraph(order.getInvoiceaddress().getTelefoonnummer(), subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de start zin 
    preface.add(new Paragraph(
            this.Getspringmessage("dear") + " " + order.getInvoiceaddress().getKlantnaam() + ",", subtitel));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(this.Getspringmessage("paymentvieuw"), subFont));
    addEmptyLine(preface, 1);
    //Aanmaken van de betaal tabel
    createTable(preface);
    //Overzicht bwt bedrag
    addEmptyLine(preface, 1);
    Paragraph btw = new Paragraph(this.Getspringmessage("taxamount") + ": " + " "
            + String.format("%.2f", (this.totaalprijs / 100) * 19), subFont);
    btw.setAlignment(Element.ALIGN_RIGHT);
    preface.add(btw);
    //Overzicht Totaalbedrag
    Paragraph Totaalbedrag = new Paragraph(
            this.Getspringmessage("totalamount") + ": " + " " + String.format("%.2f", this.totaalprijs),
            subtitel);
    Totaalbedrag.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Totaalbedrag);
    addEmptyLine(preface, 1);

    //Toevoegen footerzin
    Paragraph footer = new Paragraph(this.Getspringmessage("invoicend"), subFont);
    footer.setAlignment(Element.ALIGN_CENTER);
    preface.add(footer);
    document.add(preface);
    Mailgenerator mail = new Mailgenerator();
    mail.Sendmail("willem1995@hotmail.com", order, env, filename);
}

From source file:com.photoshop.misc.Factuurgenerator.java

private void createTable(Paragraph preface) throws BadElementException, DocumentException {
    // create header cell
    PdfPTable table = new PdfPTable(5);

    // set the width of the table to 100% of page
    table.setWidthPercentage(100);//from   w w w .  j  a v a2 s . co m
    table.setWidths(new float[] { 0.6f, 0.4f, 1.4f, 0.8f, 0.8f });
    table.setHeaderRows(1);
    creatCell(this.Getspringmessage("amount"), table, true);
    creatCell(this.Getspringmessage("photonumber"), table, true);
    creatCell(this.Getspringmessage("description"), table, true);
    creatCell(this.Getspringmessage("productprice"), table, true);
    creatCell(this.Getspringmessage("total"), table, true);

    for (OrderRow row : order.getOrderRows()) {
        creatCell(row.getAantal() + "", table, false);
        creatCell(row.getPhoto_id() + "", table, false);
        creatCell(row.getProduct().getName(), table, false);
        creatCell(" " + row.getProductprice(), table, false);

        double totaalprijsproduct = row.getProductprice() * row.getAantal();
        creatCell(" " + String.format("%.2f", totaalprijsproduct), table, false);
        totaalprijs = totaalprijs + totaalprijsproduct;
    }
    preface.add(table);
}

From source file:com.photoshop.misc.Indexkaartgenerator.java

private void addTitlePage(Document document) throws DocumentException {
    document.newPage();//from   w w w.  ja  v a  2s.  c o m
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);

    Image Logo = null;
    try {
        Logo = Image.getInstance(env.getProperty("logo") + "Photoshop_black.png");
        Logo.scaleAbsolute(200, 100);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
    }
    SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
    preface.add(Logo);
    Paragraph datum = new Paragraph(Getspringmessage("Date") + " " + simpledatafo.format(new Date()),
            smallBold);
    datum.setAlignment(Element.ALIGN_RIGHT);
    preface.add(datum);
    Paragraph Factuurnummer = new Paragraph(this.Getspringmessage("invoicenumber") + " " + order.getId(),
            smallBold);
    Factuurnummer.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Factuurnummer);
    addEmptyLine(preface, 1);

    //Aanmaken van de bedrijfs gegevens
    preface.add(new Paragraph(this.Getspringmessage("company"), subtitel));
    preface.add(new Paragraph("Rachelsmolen 1", subFont));
    preface.add(new Paragraph("5612MA Eindhoven", subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(this.Getspringmessage("accountNumber") + ": 165947888", subFont));
    preface.add(new Paragraph("Bank: Paypal", subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de bestellende persoons gegevens
    preface.add(new Paragraph(this.Getspringmessage("reciver") + ": ", subtitel));
    preface.add(new Paragraph(order.getInvoiceaddress().getKlantnaam(), subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(order.getInvoiceaddress().getAdres(), subFont));
    preface.add(new Paragraph(
            order.getInvoiceaddress().getPostcode() + " " + order.getInvoiceaddress().getWoonplaats(),
            subFont));
    preface.add(new Paragraph(order.getInvoiceaddress().getTelefoonnummer(), subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de start zin 
    preface.add(new Paragraph(this.Getspringmessage("dear") + " " + order.getInvoiceaddress().getKlantnaam(),
            subtitel));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            this.Getspringmessage("allordersby") + " " + order.getInvoiceaddress().getKlantnaam(), subFont));
    addEmptyLine(preface, 1);
    //Aanmaken van de betaal tabel
    createTable(preface);

    //Toevoegen footerzin
    Paragraph footer = new Paragraph(this.Getspringmessage("thanksforordering"), subFont);
    footer.setAlignment(Element.ALIGN_CENTER);
    preface.add(footer);

    document.add(preface);

}

From source file:com.photoshop.misc.Indexkaartgenerator.java

private void createTable(Paragraph preface) throws BadElementException, DocumentException {
    // create header cell
    PdfPTable table = new PdfPTable(4);

    // set the width of the table to 100% of page
    table.setWidthPercentage(100);/*from  ww w. j a  v  a2s  .  co  m*/
    table.setWidths(new float[] { 1f, 0.6f, 0.4f, 2f });
    table.setHeaderRows(1);
    creatCell("Voorbeeld foto", table, true);
    creatCell("Aantal", table, true);
    creatCell("PhotoID", table, true);
    creatCell("Beschrijving", table, true);

    for (OrderRow row : order.getOrderRows()) {
        Photo pfdphoto = this.photoDao.getById(row.getPhoto_id());
        Image Logo = null;
        try {
            String filename = env.getProperty("uploadDir") + "thumb/" + pfdphoto.getThumbnailURL();
            Logo = Image.getInstance(filename);
            Logo.scaleAbsolute(75, 50);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
        }
        PdfPCell c1 = new PdfPCell(Logo);
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingTop(10);
        c1.setPaddingBottom(10);
        table.addCell(c1);
        creatCell(row.getAantal() + "", table, false);
        creatCell(row.getPhoto_id() + "", table, false);
        creatCell(row.getProduct().getName(), table, false);
    }
    preface.add(table);
}