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:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printHtmlParagraphs(Section section, String content, int parentLevel) throws Exception {
    if (content == null || content.length() == 0)
        return;//w w  w  . j a v a2  s  .c om
    Paragraph comb = new Paragraph();
    ElementList list = XMLWorkerHelper.parseToElementList(content, null);
    for (Element element : list) {
        comb.add(element);
    }
    section.add(comb);
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.chaschev.itext.ParagraphBuilder.java

License:Apache License

@Override
public ParagraphBuilder withNew() {
    element = new Paragraph();
    return this;
}

From source file:com.coast.PDFPrinter_iText.java

License:Apache License

/**
 * Prints the document at its actual size. This is the recommended way to print.
 *//*w ww .  j a v  a 2s. c o  m*/
private static void print(String pFileName, String pPayload) throws IOException, Exception {
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(pFileName));
    // step 3
    document.open();
    // step 4
    String _dateTime = LocalDateTime.now().toString();
    document.addTitle("List of All Customers & their assets as of: " + _dateTime);
    document.addCreationDate();
    document.addSubject("List of All Customers & their assets as of: " + _dateTime);

    Font _font = new Font();
    _font.setColor(BaseColor.BLUE);
    _font.setStyle(Font.BOLD);
    _font.setSize(15);

    Chunk _chunk = new Chunk("List of All Customers & their assets as of: " + _dateTime);
    _chunk.setFont(_font);
    Paragraph _header = new Paragraph();
    _header.add(_chunk);
    document.add(_header);
    document.add(new Paragraph(pPayload));

    // step 5
    document.close();
}

From source file:com.cts.ptms.carrier.ups.UPSHTTPClient.java

public String createInvoicePDF(String imagePath, String OUTPUT_FILEPATH)
        throws FileNotFoundException, IOException, DocumentException, InterruptedException, URISyntaxException {

    float currPosition = 0;
    String sFilepath = OUTPUT_FILEPATH;
    Image image = Image.getInstance(imagePath);
    //create a paragraph
    Paragraph paragraph = new Paragraph();
    Document d = new Document(PageSize.A4_LANDSCAPE.rotate());
    PdfWriter w = PdfWriter.getInstance(d, new FileOutputStream(sFilepath));
    d.open();/*from w  ww .  jav a2  s  . com*/
    PdfContentByte cb = w.getDirectContent();
    ByteArrayOutputStream stampedBuffer;
    URL resource = this.getClass().getClassLoader().getResource(ShippingConstants.INVOICE_TEMPLATE);
    File file = new File(resource.toURI());
    PdfReader templateReader = new PdfReader(new FileInputStream(file));
    stampedBuffer = new ByteArrayOutputStream();
    PdfStamper stamper = new PdfStamper(templateReader, stampedBuffer);
    stamper.setFormFlattening(true);
    AcroFields form = stamper.getAcroFields();
    float[] columnWidths = { 1f, 1f, 1f, 3f };
    //create PDF table with the given widths
    PdfPTable table = new PdfPTable(columnWidths);
    // form.setField("field1", String.format("Form Text %d", i+1));
    form.setField("OBName", "Ragav");
    form.setField("OBCompany", "Ragav");
    form.setField("OBAddress", "2002 SW Sarazen Cr");
    form.setField("OBCity", "Bentonville");
    form.setField("OBPhone", "1234567890");
    form.setField("STName", "Ragav");
    form.setField("STCompany", "Ragav");
    form.setField("STAddress", "2002 SW Sarazen Cr");
    form.setField("STCity", "Bentonville");
    form.setField("STPhone", "1234567890");
    form.setField("itemNo", "12334535");
    form.setField("itemDesc", "Laundry Bag");
    stamper.close();
    templateReader.close();
    form = null;
    stamper.close();
    templateReader.close();
    PdfReader stampedReader = new PdfReader(stampedBuffer.toByteArray());
    PdfImportedPage page = w.getImportedPage(stampedReader, 1);
    cb.addTemplate(page, 0, currPosition);
    image.scaleAbsoluteHeight(325);
    image.scaleAbsoluteWidth(550);
    image.setRotationDegrees(270);
    image.setAbsolutePosition(450, 20);
    d.add(image);
    d.close();
    w.close();

    return sFilepath;
}

From source file:com.debashubham.dumpy.ChainageCalcActivity.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*w  w  w. j av a 2 s .co m*/
    // Lets write a big header
    preface.add(new Paragraph("SURVEY REPORT", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + surveyor_name + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(
            new Paragraph("This document is the report of a survey conducted on " + date_of_survey, smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document is the report of a survey with the work named as: " + work_name,
            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 the user.",
            redFont));

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

From source file:com.docdoku.server.extras.TitleBlockGenerator.java

License:Open Source License

public InputStream generateBlockTitleToPDF(InputStream inputStream) throws IOException, DocumentException {

    File tmpDir = com.google.common.io.Files.createTempDir();
    File blockTitleFile = new File(tmpDir, inputStream.toString());

    ResourceBundle bundle = ResourceBundle.getBundle(BASE_NAME, pLocale);

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(blockTitleFile));
    document.open();/* w w  w. j av a 2s. c o m*/

    // Main paragraph
    Paragraph preface = new Paragraph();
    generateHeader(preface, bundle);
    generateTable(preface, bundle);
    addEmptyLine(preface, 1);
    if (!instanceAttributes.isEmpty()) {
        generateAttribute(preface, bundle);
        addEmptyLine(preface, 1);
    }
    if (workflow != null) {
        generateLyfeCycleState(preface, bundle);
    }

    document.add(preface);

    addMetaData(document);

    document.close();

    tmpDir.deleteOnExit();

    // Merge the pdf generated with the pdf given in the input stream
    //TODO: use PdfStamper to insert into the existing pdf.
    return mergePdfDocuments(new FileInputStream(blockTitleFile), inputStream);

}

From source file:com.elsys.generator.NewPdfGenerator.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from  w  w w  .  j  ava2  s .c om*/
    // Lets write a big header
    preface.add(new Paragraph("Bitwise operations", 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:com.equiworx.util.Main.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from  w w w  . j  av  a 2 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//System.getProperty("user.name")
    preface.add(new Paragraph("Report generated by: " + "Balwinder Singh" + ", " + 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, 30);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or anycvcxvcxvcxvcxvcxvvcxvvcxcxv"
                    + "vcx" + "cxv" + "cxv" + "vcx" + "vcx" + "vcx" + "vcx" + "vcx" + "vcx" + "vcx" + "vcx"
                    + "vcxsdasdsadasdsadsaffdsafds                                                               "
                    + "vcx                                                                          "
                    + "vcx                                                          "
                    + "vcx                                                                                       "
                    + "vcx                                                                           "
                    + "vcx                                                            "
                    + "vcx                                                                                   "
                    + "vcx                                                       "
                    + "vcx                                                                       "
                    + "vcx                                                   "
                    + "vcx                                                              "
                    + "vcx                                " + "                                  "
                    + "                                 "
                    + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
                    + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + ""
                    + "                   " + "vcx" + "vcx" + "vcx" + "vcx" + "vcx" + "vcx" + "vcvc" + "vcx"
                    + "vcx" + "vcxvcxvccvcxvcxvcxvxcvcxvcxvcx"
                    + "        vbclbclkbfgkkfgfgkfgk other agreement with vogella.de ;-).",
            redFont));

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

From source file:com.etest.pdfgenerator.InventoryCasesReportPDF.java

public InventoryCasesReportPDF() {
    Document document = null;//from  w  ww.  ja  v a  2 s  .c o m
    Date date = new Date();

    try {
        document = new Document(PageSize.LETTER, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(500, 700);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph reportTitle = new Paragraph();
        reportTitle.setAlignment(Element.ALIGN_CENTER);
        reportTitle.add(new Phrase("Inventory of Cases Report", header));
        document.add(reportTitle);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted.add(
                new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), dateFont));
        document.add(datePrinted);

        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 100, 300, 100, 100 });
        table.setSpacingAfter(5f);

        PdfPCell cellOne = new PdfPCell(new Phrase("Subject"));
        cellOne.setBorder(Rectangle.NO_BORDER);
        cellOne.setPaddingLeft(10);
        cellOne.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Descriptive Title"));
        cellTwo.setBorder(Rectangle.NO_BORDER);
        cellTwo.setPaddingLeft(10);
        cellTwo.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase("No. of Cases"));
        cellThree.setBorder(Rectangle.NO_BORDER);
        cellThree.setPaddingLeft(10);
        cellThree.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase("No. of Items"));
        cellFour.setBorder(Rectangle.NO_BORDER);
        cellFour.setPaddingLeft(10);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);

        table.getDefaultCell().setBorderWidth(0f);
        document.add(table);

        for (InventoryOfCasesReport report : service.getInventoryOfCases()) {
            PdfPTable table2 = new PdfPTable(4);
            table2.setWidthPercentage(100);
            table2.setWidths(new int[] { 100, 300, 100, 100 });
            table2.setSpacingBefore(3f);
            table2.setSpacingAfter(3f);

            if (!service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()).isEmpty()) {
                if (!service
                        .getListOfCellCaseIdBySyllabusId(
                                service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))
                        .isEmpty()) {
                    PdfPCell cell1 = new PdfPCell(new Paragraph(report.getSubject(), content));
                    cell1.setBorder(0);
                    cell1.setPaddingLeft(10);
                    cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell2 = new PdfPCell(new Paragraph(report.getDescriptiveTitle(), content));
                    cell2.setBorder(0);
                    cell2.setPaddingLeft(10);
                    cell2.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell3 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellCasesBySyllabus(
                                    service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))),
                            content));
                    cell3.setBorder(0);
                    cell3.setPaddingLeft(10);
                    cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell4 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellItemsByCellCaseId(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())))),
                            content));
                    cell4.setBorder(0);
                    cell4.setPaddingLeft(10);
                    cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    table2.addCell(cell1);
                    table2.addCell(cell2);
                    table2.addCell(cell3);
                    table2.addCell(cell4);
                    document.add(table2);
                }
            }
        }
    } catch (DocumentException ex) {
        Logger.getLogger(InventoryItemsReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.etest.pdfgenerator.InventoryItemsReportPDF.java

public InventoryItemsReportPDF() {
    Document document = null;//from  w  ww  . j ava  2  s.co m
    Date date = new Date();

    try {
        document = new Document(PageSize.LETTER.rotate(), 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(650, 500);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph title1 = new Paragraph();
        title1.setAlignment(Element.ALIGN_CENTER);
        title1.add(new Phrase("Inventory of Items Report"));
        document.add(title1);

        Paragraph title2 = new Paragraph();
        title2.setAlignment(Element.ALIGN_CENTER);
        title2.add(new Phrase("Grouped According to the Revised Bloom's Taxonomy"));
        document.add(title2);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted
                .add(new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), content));
        document.add(datePrinted);

        PdfPTable table = new PdfPTable(8);
        table.setWidthPercentage(100);
        table.setSpacingAfter(5f);

        for (int i = 0; i < tableHeader.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(tableHeader[i], header));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingLeft(10);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            if (tableHeader[i].equals("Subject")) {
                cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            } else {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            }
            table.addCell(cell);
        }

        document.add(table);

        for (InventoryOfCasesReport report : service.getInventoryOfCases()) {
            PdfPTable table2 = new PdfPTable(8);
            table2.setWidthPercentage(100);
            table2.setSpacingBefore(3f);
            table2.setSpacingAfter(3f);

            if (!service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()).isEmpty()) {
                if (!service
                        .getListOfCellCaseIdBySyllabusId(
                                service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))
                        .isEmpty()) {
                    PdfPCell cell1 = new PdfPCell(new Paragraph(report.getSubject(), content));
                    cell1.setBorder(0);
                    cell1.setPaddingLeft(10);
                    cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell2 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Remember.toString()))), content));
                    cell2.setBorder(0);
                    cell2.setPaddingLeft(10);
                    cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell3 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Understand.toString()))), content));
                    cell3.setBorder(0);
                    cell3.setPaddingLeft(10);
                    cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell4 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Apply.toString()))), content));
                    cell4.setBorder(0);
                    cell4.setPaddingLeft(10);
                    cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell5 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Analyze.toString()))), content));
                    cell5.setBorder(0);
                    cell5.setPaddingLeft(10);
                    cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell6 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Evaluate.toString()))), content));
                    cell6.setBorder(0);
                    cell6.setPaddingLeft(10);
                    cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell7 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Create.toString()))), content));
                    cell7.setBorder(0);
                    cell7.setPaddingLeft(10);
                    cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell8 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellItemsByCellCaseId(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())))),
                            content));
                    cell8.setBorder(0);
                    cell8.setPaddingLeft(10);
                    cell8.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell8.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    table2.addCell(cell1);
                    table2.addCell(cell2);
                    table2.addCell(cell3);
                    table2.addCell(cell4);
                    table2.addCell(cell5);
                    table2.addCell(cell6);
                    table2.addCell(cell7);
                    table2.addCell(cell8);
                    document.add(table2);
                }
            }
        }
    } catch (DocumentException ex) {
        Logger.getLogger(InventoryItemsReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}