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:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java

License:Apache License

/**
 * Export a report to a pdf file./* w ww. j a v  a  2 s. c  o  m*/
 *
 * @param allMetricsMap         map of all QC metrics - keys and description.
 * @param selectedReports       the report units to be exported in PDF format.
 * @param preferredPDFDirectory the directory the pdf document should be exported to.
 * @return Path of the created PDF document if it is successfully created - otherwise return empty string.
 */
public static String exportReportUnitInPDFFormat(final Map<String, String> allMetricsMap,
        final ArrayList<ReportUnit> selectedReports, final String preferredPDFDirectory) {
    //Obtain current timestamp. 
    final java.util.Date date = new java.util.Date();
    final String timestampString = CREATION_DATE_TIME_FORMAT.format(date);
    //Replace all occurrences of special character ':' from time stamp since ':' is not allowed in filename. 
    final String filenameTimestamp = timestampString.replace(':', '-');
    //Instantiation of document object - landscape format using the rotate() method
    final Document document = new Document(PageSize.A4.rotate(), PDF_PAGE_MARGIN, PDF_PAGE_MARGIN,
            PDF_PAGE_MARGIN, PDF_PAGE_MARGIN);
    final String pdfFileName = preferredPDFDirectory + "\\QCReports-" + filenameTimestamp + FILE_TYPE_EXTENSION;
    try {
        //Creation of PdfWriter object
        //            PdfWriter writer;
        //            writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName));
        document.open();
        for (ReportUnit reportUnit : selectedReports) {
            //New page for each report. 
            document.newPage();
            //Creation of chapter object
            final Paragraph pageTitle = new Paragraph(
                    String.format(PDF_PAGE_TITLE, reportUnit.getMsrunName(), timestampString),
                    Constants.PDF_TITLE_FONT);
            pageTitle.setAlignment(Element.ALIGN_CENTER);
            final Chapter chapter1 = new Chapter(pageTitle, 1);
            chapter1.setNumberDepth(0);
            //Creation of TIC graph section object
            final String graphTitle = String.format(TIC_GRAPH_SECTION_TITLE, reportUnit.getMsrunName());
            final Paragraph ticGraphSection = new Paragraph(graphTitle, Constants.PDF_SECTION_FONT);
            ticGraphSection.setSpacingBefore(PDF_PARAGRAPH_SPACING);
            ticGraphSection.add(Chunk.NEWLINE);
            //Insert TIC Graph in ticGraphSection.
            ticGraphSection.add(createTICChartImage(reportUnit));
            chapter1.addSection(ticGraphSection);
            final String metricsTitle = String.format(METRICS_VALUES_SECTION_TITLE, reportUnit.getMsrunName());
            final Paragraph metricsValuesSection = new Paragraph(metricsTitle, Constants.PDF_SECTION_FONT);
            metricsValuesSection.setSpacingBefore(PDF_PARAGRAPH_SPACING);
            //Reference: http://www.java-connect.com/itext/add-table-in-PDF-document-using-java-iText-library.html
            //TODO: Insert metrics values table in metricsValuesSection
            metricsValuesSection.add(createMetricsValuesTable(allMetricsMap, reportUnit));
            chapter1.addSection(metricsValuesSection);
            //Addition of a chapter to the main document
            document.add(chapter1);
        }
        document.close();
        return pdfFileName;
    } catch (final DocumentException e) {
        // TODO Explain when these exception can occur.
        /* FileNotFoundException will be thrown by the FileInputStream, FileOutputStream, and 
         * RandomAccessFile constructors when a file with the specified path name does not exist.
         * It will also be thrown by these constructors if the file does exist but for some reason 
         * is inaccessible, for example when an attempt is made to open a read-only file for writing.
         * DocumentException Signals that an error has occurred in a Document.
         */
        logger.log(Level.SEVERE, PDF_EXPORT_EXCEPTION_MESSAGE, e);
        return "";
    }
}

From source file:nl.infosys.hartigehap.barSystem.domain.Bon.java

/**
 * create the table for the PDF//from ww w  .j a v a2 s.com
 *
 * @return table
 */
private Paragraph table() {

    Paragraph par = new Paragraph();

    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell;

    Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD);
    Font normal = FontFactory.getFont("Times-Roman", 13);

    table.addCell(new Phrase("Product:", fontbold));
    table.addCell(new Phrase("Prijs:", fontbold));
    table.addCell(new Phrase("Aantal:", fontbold));
    table.addCell(new Phrase("Totaalprijs:", fontbold));

    for (ImmutableProduct product : bestelling.getProducten()) {
        table.addCell(new Phrase(product.getNaam(), normal));
        table.addCell(new Phrase(product.getPrijsFormat(), normal));
        table.addCell(new Phrase(String.valueOf(product.getAantal()), normal));

        cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("Excl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("BTW 21%", fontbold));
    cell.setBorder(0);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold));
    cell.setColspan(4);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Incl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);
    par.add(table);

    return par;
}

From source file:nl.infosys.hartigehap.barSystem.presentation.BonGui.java

private Paragraph table() {

    Paragraph par = new Paragraph();

    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100);//from   w  w  w  . j  a  va 2 s .  c o m
    table.getDefaultCell().setBorder(0);
    PdfPCell cell;

    Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD);
    Font normal = FontFactory.getFont("Times-Roman", 13);

    table.addCell(new Phrase("Product:", fontbold));
    table.addCell(new Phrase("Prijs:", fontbold));
    table.addCell(new Phrase("Aantal:", fontbold));
    table.addCell(new Phrase("Totaalprijs:", fontbold));

    for (ImmutableProduct product : bestelling.getProducten()) {
        table.addCell(new Phrase(product.getNaam(), normal));
        table.addCell(new Phrase(product.getPrijsFormat(), normal));
        table.addCell(new Phrase(String.valueOf(product.getAantal()), normal));

        cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(0);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("Excl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("BTW 21%", fontbold));
    cell.setBorder(0);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold));
    cell.setColspan(4);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Incl. BTW", fontbold));
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold));
    cell.setColspan(3);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);
    par.add(table);

    return par;
}

From source file:numerical.CramersRule.java

private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed
    JFileChooser jfc = new JFileChooser();
    jfc.setCurrentDirectory(new File("/My Documents"));
    int return_val = jfc.showSaveDialog(rootPane);
    if (return_val == JFileChooser.APPROVE_OPTION) {
        Document doc = new Document();
        try {//from   www . j  a va  2s  .c om
            jfc.getSelectedFile();
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(jfc.getSelectedFile() + ".pdf"));
            doc.open();

            Font f = new Font(Font.FontFamily.TIMES_ROMAN, 12.0f, Font.NORMAL, BaseColor.BLACK);
            Font f1 = new Font(Font.FontFamily.TIMES_ROMAN, 18.0f, Font.BOLD, BaseColor.BLACK);

            Paragraph paragraph = new Paragraph(null, f);
            Paragraph title = new Paragraph(null, f1);
            title.add("Cramers Rule\n");

            paragraph.add(txt_result.getText());
            doc.add(title);
            doc.add(paragraph);
            doc.close();
            writer.close();

            JOptionPane.showMessageDialog(rootPane, "Successfully saved!");
        } catch (FileNotFoundException | DocumentException | HeadlessException e) {
            System.err.println(e);
        }
    }
}

From source file:numerical.Determinants.java

private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed
    JFileChooser jfc = new JFileChooser();
    jfc.setCurrentDirectory(new File("/My Documents"));
    int return_val = jfc.showSaveDialog(rootPane);
    if (return_val == JFileChooser.APPROVE_OPTION) {
        Document doc = new Document();
        try {/*from  w  ww.j  a v  a2s .c om*/
            jfc.getSelectedFile();
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(jfc.getSelectedFile() + ".pdf"));
            doc.open();

            Font f = new Font(Font.FontFamily.TIMES_ROMAN, 12.0f, Font.NORMAL, BaseColor.BLACK);
            Font f1 = new Font(Font.FontFamily.TIMES_ROMAN, 18.0f, Font.BOLD, BaseColor.BLACK);

            Paragraph paragraph = new Paragraph(null, f);
            Paragraph title = new Paragraph(null, f1);
            title.add("Determinants \n");

            paragraph.add(txt_result.getText());
            doc.add(title);
            doc.add(paragraph);
            doc.close();
            writer.close();

            JOptionPane.showMessageDialog(rootPane, "Successfully saved!");
        } catch (FileNotFoundException | DocumentException | HeadlessException e) {
            System.err.println(e);
        }
    }
}

From source file:numerical.Fibonnaci.java

private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed
    JFileChooser jfc = new JFileChooser();
    jfc.setCurrentDirectory(new File("/My Documents"));
    int return_val = jfc.showSaveDialog(rootPane);
    if (return_val == JFileChooser.APPROVE_OPTION) {
        Document doc = new Document();
        try {/*from   w  w w . j a v  a 2s. co  m*/
            jfc.getSelectedFile();
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(jfc.getSelectedFile() + ".pdf"));
            doc.open();

            Font f = new Font(Font.FontFamily.TIMES_ROMAN, 12.0f, Font.NORMAL, BaseColor.BLACK);
            Font f1 = new Font(Font.FontFamily.TIMES_ROMAN, 18.0f, Font.BOLD, BaseColor.BLACK);

            Paragraph paragraph = new Paragraph(null, f);
            Paragraph title = new Paragraph(null, f1);
            title.add("Fibonnaci\n");
            paragraph.add("Sequence number: " + count + "\n");
            paragraph.add("Result: ");
            paragraph.add(txt_result.getText());
            doc.add(title);
            doc.add(paragraph);
            doc.close();
            writer.close();

            JOptionPane.showMessageDialog(rootPane, "Successfully saved!");
        } catch (FileNotFoundException | DocumentException | HeadlessException e) {
            System.err.println(e);
        }
    }
}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private void addParagraphToTableSoilName(PdfPTable t, String key, String value) {
    PdfPCell c;//  ww w  .  j a va2 s.  co m
    Paragraph p = new Paragraph();

    Chunk keyChunk = new Chunk(key, BLACK_NORMAL);
    Chunk valChunk = new Chunk(value, BLACK_BOLD);

    p.add(keyChunk);
    p.add(valChunk);

    c = new PdfPCell(p);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    c.setBorder(0);
    t.addCell(c);
}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private void addUserDetails(PdfPTable t, String key, String value) {
    PdfPCell c;//  ww  w.  j  av  a2 s .c  om
    Paragraph p = new Paragraph();

    Chunk keyChunk = new Chunk(key, BLACK_NORMAL);
    Chunk valChunk = new Chunk(value, BLACK_BOLD);

    p.add(keyChunk);
    p.add(valChunk);

    c = new PdfPCell(p);
    c.setHorizontalAlignment(Element.ALIGN_LEFT);
    c.setBorder(0);
    t.addCell(c);
}

From source file:org.arc42.pdfutil.PdfConcatenizer.java

License:Open Source License

private static void addBlankLines(Paragraph paragraph, int nrOfLines) {
    for (int i = 0; i < nrOfLines; i++) {
        paragraph.add(new Paragraph(" "));
    }//ww w .  j  av a2s  .  c  om
}

From source file:org.bonitasoft.studio.migration.utils.PDFMigrationReportWriter.java

License:Open Source License

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // Lets write a big header
    preface.add(new Paragraph(report.getName(), catFont));
    //addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph(
            new SimpleDateFormat("dd MMM yyyy", new Locale(Platform.getNL())).format(new Date()), smallBold));
    document.add(preface);/* w  ww. j  a v  a  2  s  .  c  om*/

}