Example usage for com.itextpdf.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph() 

Source Link

Document

Constructs a Paragraph.

Usage

From source file:PDFmaker.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/* ww  w .j  a  v  a2  s . c o  m*/
    // Lets write a big header
    preface.add(new Paragraph("Productielijst", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(
            new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + LocalDate.now(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    smallBold));
    //        addEmptyLine(preface, 3);
    //        preface.add(new Paragraph(
    //                "This document describes something which is very important ",
    //                smallBold));
    //
    //        addEmptyLine(preface, 8);
    //
    //        preface.add(new Paragraph(
    //                "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //                redFont));    
    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:Pdfsave.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*  w ww  .j a  va2  s .  c om*/
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:pdf_demo2.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph paragraph = new Paragraph();
    // We add one empty line
    addEmptyLine(paragraph, 1);/*from   w  w w.  jav  a2s .  co  m*/
    // Lets write a big header
    paragraph.add(new Paragraph("Title of the document", titleFont));

    addEmptyLine(paragraph, 1);
    // Will create: Report generated by: _name, _date
    paragraph.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(),
            smallBold));
    addEmptyLine(paragraph, 3);
    paragraph.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(paragraph, 8);
    paragraph.add(
            new Paragraph("This document is a preliminary version and not subject to your license agreement "
                    + "or any other agreement with vogella.com ;-).", redFont));

    document.add(paragraph);
    // Start a new page
    document.newPage();
}

From source file:EmployeeInfo.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    String value1 = txt_empID.getText();
    String value2 = txt_firstName.getText();
    String value3 = txt_lastName.getText();
    String value4 = txt_age.getText();

    try {/* w ww.j  av a  2  s.co m*/
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Report1.pdf"));
        document.open();
        //add barcode
        PdfContentByte CB = writer.getDirectContent();
        BarcodeEAN codEAN = new BarcodeEAN();
        codEAN.setCode("1234567891023"); //this value must be 13 digits
        Paragraph para = new Paragraph();
        document.add(new Paragraph("Barcode UDCA"));
        codEAN.setCodeType(BarcodeEAN.UPCA);
        codEAN.setCode("1098765432112");
        document.add(codEAN.createImageWithBarcode(CB, BaseColor.BLACK, BaseColor.BLACK));
        document.add(para);

        Image image = Image.getInstance("images/Cherry.png");
        document.add(new Paragraph("Image"));
        document.add(image);

        // write tile with style
        document.add(new Paragraph("Hello World",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        // write date
        document.add(new Paragraph(new Date().toString()));
        document.add(new Paragraph("--------------------------------------------"));
        PdfPTable table = new PdfPTable(2);// 2 columns
        // set title , column sapn, aliignment,background color
        PdfPCell cell = new PdfPCell(new Paragraph("Title"));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.BLUE);
        table.addCell(cell);
        // PdfPTable table = new PdfPTable(x); should add multiple of x
        table.addCell("EmployeeID");
        table.addCell(value1);
        table.addCell("Name");
        table.addCell(value2);
        table.addCell("Last Name");
        table.addCell(value3);
        table.addCell("Age");
        table.addCell(value4);
        document.add(table);
        List list = new List(true, 20);
        list.add("First Item");
        list.add("Second Item");
        list.add("Third Item");
        list.add("Fourth Item");
        document.add(list);
        document.close();
        JOptionPane.showMessageDialog(null, "Report saved");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:be.kcbj.placemat.Placemat.java

License:Open Source License

private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException {
    int numLines = 0;
    Paragraph p = new Paragraph();

    if (sponsor.image != null) {
        Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image));
        if (sponsor.imageWidth != 0) {
            image.scaleToFit(sponsor.imageWidth, 1000);
        } else if (sponsor.imageHeight != 0) {
            image.scaleToFit(1000, sponsor.imageHeight);
        }//ww  w .j a v a2s.c  o  m
        Chunk imageChunk = new Chunk(image, 0, 0, true);
        p.add(imageChunk);
    }

    if (sponsor.twoColumns) {
        StringBuilder sb = new StringBuilder();
        if (sponsor.name != null) {
            sb.append(sponsor.name);
        }
        if (sponsor.name2 != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.name2);
        }
        if (sponsor.address != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.address);
        }
        if (sponsor.address2 != null) {
            if (sb.length() > 0) {
                sb.append(" - ");
            }
            sb.append(sponsor.address2);
        }
        p.add(Chunk.NEWLINE);
        p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL)));
        numLines++;
    } else {
        if (sponsor.twoRows && sponsor.image != null) {
            p.add(Chunk.NEWLINE);
        }
        if (sponsor.name != null) {
            p.add(generateFittedChunk(sponsor.name, Font.BOLD));
            numLines++;
        }
        if (sponsor.name2 != null) {
            p.add(Chunk.NEWLINE);
            p.add(generateFittedChunk(sponsor.name2, Font.BOLD));
            numLines++;
        }
        if (sponsor.address != null) {
            p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL)));
            p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
            numLines++;
        }
        if (sponsor.address2 != null) {
            p.add(Chunk.NEWLINE);
            p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL)));
            numLines++;
        }
    }
    p.setPaddingTop(0);
    p.setSpacingBefore(0);
    p.setAlignment(Element.ALIGN_CENTER);
    p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f);

    PdfPCell cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setFixedHeight(cellHeight);
    if (sponsor.twoColumns) {
        cell.setColspan(2);
    }
    if (sponsor.twoRows) {
        cell.setRowspan(2);
        if (sponsor.image == null) {
            p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f);
        }
    }
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setCellEvent(CELL_EVENT);
    cell.setPaddingBottom(4);
    cell.addElement(p);
    if (sponsor.isTodo()) {
        cell.setBackgroundColor(BaseColor.ORANGE);
    }

    return cell;
}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable createModelPage(Contact contact, Model model, PdfWriter pdfWriter)
        throws IOException, DocumentException {

    final PdfPTable pdfPTable = new PdfPTable(new float[] { 40f, 1f, 59f });
    pdfPTable.setTotalWidth(iTextUtil.PAGE_SIZE.getWidth());
    pdfPTable.addCell(cell(buildModelDetailSection(model, pdfWriter)));
    pdfPTable.addCell(cell(new Paragraph()));
    pdfPTable.addCell(cell(buildModelPricingTables(contact, model)));
    return pdfPTable;

}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPCell createRow(String key, String value, String url) {
    final Paragraph paragraph = new Paragraph();
    paragraph.add(new Chunk(key, iTextUtil.getFontModelKey()));
    paragraph.add(new Chunk(": ", iTextUtil.getFontModelKey()));

    if (value == null) {
        value = "";
    }/*  ww  w  . ja  va 2 s  .  c o m*/

    final Phrase valuePhrase = processHtmlCodes(value.trim(), iTextUtil.getFontModelValue(),
            iTextUtil.getFontModelSymbol());
    if (!StringUtils.isEmpty(url)) {
        for (Chunk chunk : valuePhrase.getChunks()) {
            chunk.setAction(new PdfAction(url));
        }
    }
    for (Chunk chunk : valuePhrase.getChunks()) {
        chunk.setLineHeight(13f);
    }
    paragraph.add(valuePhrase);

    final PdfPCell cell = cell(paragraph);
    cell.setPaddingBottom(5f);
    return cell;
}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private byte[] personalize(byte[] pdf, Contact contact, Toc tableOfContents)
        throws IOException, DocumentException {

    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {

        final PdfReader reader = new PdfReader(pdf);
        final PdfStamper stamper = new PdfStamper(reader, bos);

        // stamp some text on first page
        PdfContentByte text = stamper.getOverContent(1);

        text.beginText();//from   www  .j ava  2s.c  om

        text.setColorFill(iTextUtil.getFontCoverText().getColor());
        text.setFontAndSize(iTextUtil.getFontCoverText().getBaseFont(), iTextUtil.getFontCoverText().getSize());
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle1,
                text.getPdfDocument().getPageSize().getWidth() - 15, 195, 0);
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle2,
                text.getPdfDocument().getPageSize().getWidth() - 15, 175, 0);
        text.showTextAligned(Element.ALIGN_RIGHT, contact.getCurrency().getTitlePageDescription(),
                text.getPdfDocument().getPageSize().getWidth() - 15, 80, 0);

        text.setColorFill(iTextUtil.getFontCoverPricingguide().getColor());
        text.setFontAndSize(iTextUtil.getFontCoverPricingguide().getBaseFont(),
                iTextUtil.getFontCoverPricingguide().getSize());
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle3,
                text.getPdfDocument().getPageSize().getWidth() - 15, 145, 0);

        text.setColorFill(iTextUtil.getFontCoverYear().getColor());
        text.setFontAndSize(iTextUtil.getFontCoverYear().getBaseFont(), iTextUtil.getFontCoverYear().getSize());
        text.showTextAligned(Element.ALIGN_RIGHT, coverTitle4,
                text.getPdfDocument().getPageSize().getWidth() - 15, 105, 0);

        text.endText();

        // stamp some text on first page of the table of contents page
        final Image logoImage = iTextUtil.getImageFromByteArray(HttpUtil.readByteArray(
                pdfTemplate.getLogo().getUrl(), defaultService.getUserName(), defaultService.getPassword()));
        final PdfContentByte tocContent = stamper.getOverContent(tableOfContents.getFirstPageOfToc());
        final float resizeRatio = logoImage.getHeight() / 85; // define the desired height of the log
        tocContent.addImage(logoImage, logoImage.getWidth() / resizeRatio, 0, 0,
                logoImage.getHeight() / resizeRatio, 59, 615);

        text = stamper.getOverContent(tableOfContents.getFirstPageOfToc());

        text.beginText();

        text.setColorFill(iTextUtil.getFontPersonalization().getColor());
        text.setFontAndSize(iTextUtil.getFontPersonalization().getBaseFont(),
                iTextUtil.getFontPersonalization().getSize());
        text.showTextAligned(Element.ALIGN_LEFT, "Prepared for:", 355, 681, 0);
        text.showTextAligned(Element.ALIGN_LEFT, contact.getFullName(), 355, 662, 0);

        // set company name
        if (!StringUtils.isEmpty(contact.getCompany())) {
            text.showTextAligned(Element.ALIGN_LEFT, contact.getCompany(), 355, 643, 0);
            text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355,
                    624, 0);
        } else {
            text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355,
                    643, 0);
        }

        text.endText();

        final ColumnText ct = new ColumnText(tocContent);
        ct.setSimpleColumn(new Rectangle(55, 517, iTextUtil.PAGE_SIZE.getWidth() - 45, 575));
        final List<Element> elements = HTMLWorker.parseToList(new StringReader(disclaimer), null);
        final Paragraph p = new Paragraph();
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        for (Element element : elements) {
            for (Chunk chunk : element.getChunks()) {
                chunk.setFont(iTextUtil.getFontDisclaimer());
            }
            p.add(element);
        }
        ct.addElement(p);
        ct.go();

        stamper.close();
        reader.close();
        return bos.toByteArray();

    }

}

From source file:bl.pdf.PDFFile.java

public void createReport(String titel, EntityTableModel tModel) throws DocumentException {
    document.open();/*from w  w w. j  a v a  2 s .c  o m*/
    Paragraph preface = new Paragraph();

    preface.add(newLine(titel, catFont, -1));
    addEmptyLine(preface, 2);

    preface.add(getTable(tModel));

    document.add(preface);
    // Start a new page
    document.newPage();
    document.close();
}

From source file:bl.pdf.PDFFile.java

public void createRechnung(Rechnung r) throws DocumentException, DALException {
    document.open();//from  w  w  w  .  j  ava  2s. c o m
    Paragraph preface = new Paragraph();

    preface.add(newLine(new Date().toString(), small, Element.ALIGN_RIGHT));

    // Lets write a big header
    preface.add(newLine("Rechnung", catFont, -1));
    preface.add(newLine(r.getValues(), small, Element.ALIGN_LEFT));

    // Will create: Report generated by: _name, _date
    String to = "";
    if (r instanceof Ausgangsrechnung) {
        Kunde k = BL.getKunde(((Ausgangsrechnung) r).getKundeID());
        to += k.getValues();
    } else if (r instanceof Eingangsrechnung) {
        Kontakt k = BL.getKontakt(((Eingangsrechnung) r).getKontaktID());
        to += k.getValues();
    }
    preface.add(newLine(to, smallBold, Element.ALIGN_RIGHT));

    // We add one empty line
    addEmptyLine(preface, 2);

    // add table
    preface.add(getRechnungszeileTable(r));

    document.add(preface);
    // Start a new page
    document.newPage();
    document.close();
}