Example usage for com.itextpdf.text Chapter add

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

Introduction

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

Prototype

@Override
public boolean add(final Element element) 

Source Link

Document

Adds a Paragraph, List, Table or another Section to this Section.

Usage

From source file:PDFmaker.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Productielijst", catFont);
    //        anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 0);
    catPart.add(new Paragraph(
            "Productielijst gegenereerd door: " + System.getProperty("user.name") + ", " + LocalDate.now(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));/*from  w  w  w.  j  a  v a2 s.  co m*/
    //        Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    //        Section subCatPart = catPart.addSection(subPara);
    //        subCatPart.add(new Paragraph("Hello"));
    //
    //        subPara = new Paragraph("Subcategory 2", subFont);
    //        subCatPart = catPart.addSection(subPara);
    //        subCatPart.add(new Paragraph("Paragraph 1"));
    //        subCatPart.add(new Paragraph("Paragraph 2"));
    //        subCatPart.add(new Paragraph("Paragraph 3"));
    //
    //        // add a list
    //        createList(subCatPart);
    //        Paragraph paragraph = new Paragraph();
    //        addEmptyLine(paragraph, 5);
    //        subCatPart.add(paragraph);

    // add a table
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 1);
    catPart.add(paragraph);
    createTable(catPart);

    // now add all this to the document
    document.add(catPart);

    //        // Next section
    //        anchor = new Anchor("Second Chapter", catFont);
    //        anchor.setName("Second Chapter");
    //
    //        // Second parameter is the number of the chapter
    //        catPart = new Chapter(new Paragraph(anchor), 1);
    //
    //        subPara = new Paragraph("Subcategory", subFont);
    //        subCatPart = catPart.addSection(subPara);
    //        subCatPart.add(new Paragraph("This is a very important message"));
    //
    //        // now add all this to the document
    //        document.add(catPart);

}

From source file:at.jps.sanction.core.io.file.PDFFileOutputWorker.java

License:Open Source License

@Override
public void handleMessage(final AnalysisResult message) {

    super.handleMessage(message);

    try {//from   ww  w .j  a  v a 2  s .c  om

        logger.info("write Message: " + message.getMessage().getId());

        final Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(getFilename()));
        document.open();

        final Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD);
        final Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL);

        Chunk chunk = new Chunk("Message", chapterFont);
        Chapter chapter = new Chapter(new Paragraph(chunk), 1);
        chapter.setNumberDepth(0);
        chapter.add(new Paragraph(message.getMessage().toString(), paragraphFont));
        document.add(chapter);

        getWriter().write(message.getMessage().toString());

        if (message.getHitList() != null) {

            chapter.add(new Paragraph("Hits", paragraphFont));

            for (final HitResult hit : message.getHitList()) {
                final PdfPTable table = new PdfPTable(2);

                table.addCell("Description");
                table.addCell(hit.getHitDescripton());
                table.addCell("Field");
                table.addCell(hit.getHitDescripton());
                table.addCell("Absolute Value");
                table.addCell(hit.getAbsolutHit() + "");
                table.addCell("Relative Value");
                table.addCell(hit.getRelativeHit() + "");
                table.addCell("Phrase Value");
                table.addCell(hit.getPhraseHit() + "");
                table.addCell("HitType");
                table.addCell(hit.getHitType());

                document.add(table);
            }
        } else {
            final String exception = message.getException();
            if (exception != null) {
                chunk = new Chunk("Error:", chapterFont);
                chapter = new Chapter(new Paragraph(chunk), 1);
                chapter.add(new Paragraph(message.getException().toString(), paragraphFont));
                document.add(chapter);
            }
        }
        document.close();
    } catch (final Exception e) {
        logger.error("Error writing to file:" + getFilename());
        logger.debug("Exception: ", e);
    }
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void populateChapter(TreeObject treeObject, Chapter chapter) throws DocumentException {
    // If there are children, don't display this object's data
    if ((treeObject.getChildObjects() == null) || (treeObject.getChildObjects().size() == 0)) {
        // Create the Data Paragraphs (displayObjects)
        if ((treeObject.getDisplayData() != null)
                && (treeObject.getDisplayData().getDisplayObjects() != null)) {
            for (DisplayObject displayObject : treeObject.getDisplayData().getDisplayObjects()) {
                Paragraph paragraph = new Paragraph(displayObject.getTitle(), sectionTitleFont);

                paragraph.add("\n");
                createDataSection(paragraph, displayObject);

                chapter.addSection(paragraph);
            }/*from   w  ww .j av  a2s .  c  o  m*/
        }
    }
    // If there are children, display them
    else {
        for (TreeObject childTreeObject : treeObject.getChildObjects()) {
            Paragraph title = new Paragraph(childTreeObject.getTitle(), sectionTitleFont);
            Paragraph content = new Paragraph("\n");

            generateData(content, childTreeObject);

            chapter.addSection(title);
            chapter.add(content);
        }
    }
}

From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java

License:Apache License

public static void setLastPageInfo(Document doc, PdfWriter writer, int cNum) throws Exception {
    Chapter chapter = PDFWriterUtil.getChapter(MessageUtil.getMessage("pdf.message.chapter.confirm.title"),
            cNum);//from  www  .  ja  va2 s .co  m

    Paragraph preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.prepared1"),
            PDFWriterUtil.fnNormalBold));
    preP.add(new Phrase("                                                           ",
            new Font(bfKorean, 10, Font.UNDERLINE)));
    preP.setSpacingBefore(15);
    preP.setSpacingAfter(2);
    chapter.add(preP);

    preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.prepared2"),
            PDFWriterUtil.fnNormal));
    preP.setIndentationLeft(65);
    preP.setSpacingAfter(14);
    chapter.add(preP);

    preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.approved1"),
            PDFWriterUtil.fnNormalBold));
    preP.add(new Phrase("                                                           ",
            new Font(bfKorean, 10, Font.UNDERLINE)));
    preP.setSpacingBefore(15);
    preP.setSpacingAfter(2);
    chapter.add(preP);

    preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.approved2"),
            PDFWriterUtil.fnNormal));
    preP.setIndentationLeft(65);
    preP.setSpacingAfter(14);
    chapter.add(preP);

    cNum++;
    doc.add(chapter);

    chapter = PDFWriterUtil.getChapter(MessageUtil.getMessage("pdf.message.chapter.appendices.title"), cNum);
    Section section = PDFWriterUtil.getSection(chapter,
            MessageUtil.getMessage("pdf.message.chapter.appendices.label1"));

    Chunk url = new Chunk(MessageUtil.getMessage("pdf.message.chapter.appendices.text1"), PDFWriterUtil.fnURL);
    url.setAction(new PdfAction(new URL(MessageUtil.getMessage("pdf.message.chapter.appendices.text1"))));

    preP = new Paragraph(url);
    preP.setIndentationLeft(23);
    preP.setSpacingAfter(14);
    section.add(preP);

    section = PDFWriterUtil.getSection(chapter,
            MessageUtil.getMessage("pdf.message.chapter.appendices.label2"));

    doc.add(chapter);
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printGraph(DocWriter writer, ProcessCanvas canvas, Process process, Rectangle pageSize,
        Chapter chapter) throws Exception {
    Dimension graphsize = getGraphSize(process);
    // we create a template and a Graphics2D object that corresponds with it
    int w;//from  w ww. ja va  2  s .  co  m
    int h;
    float scale;
    if ((float) graphsize.width < pageSize.getWidth() * 0.8
            && (float) graphsize.height < pageSize.getHeight() * 0.8) {
        w = graphsize.width + 36;
        h = graphsize.height + 36;
        scale = -1f;
    } else {
        scale = pageSize.getWidth() * 0.8f / (float) graphsize.width;
        if (scale > pageSize.getHeight() * 0.8f / (float) graphsize.height)
            scale = pageSize.getHeight() * 0.8f / (float) graphsize.height;
        w = (int) (graphsize.width * scale) + 36;
        h = (int) (graphsize.height * scale) + 36;
    }
    Image img;
    canvas.setBackground(Color.white);
    PdfContentByte cb = ((PdfWriter) writer).getDirectContent();
    PdfTemplate tp = cb.createTemplate(w, h);
    Graphics2D g2 = tp.createGraphics(w, h);
    if (scale > 0)
        g2.scale(scale, scale);
    tp.setWidth(w);
    tp.setHeight(h);
    canvas.paintComponent(g2);
    g2.dispose();
    img = new ImgTemplate(tp);
    chapter.add(img);
}

From source file:com.farouk.projectapp.ManagerGUI.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    String pdfName = JOptionPane.showInputDialog(rootPane, "Enter Title", "Please enter a title", WIDTH);
    if (pdfName.isEmpty()) {
        pdfName = "Global Report";
    }//  ww w.  jav  a  2s . c o m
    Document document = new Document();
    int numEMployees = 1;

    try {
        PdfWriter.getInstance(document, new FileOutputStream(pdfName + ".pdf"));

        document.open();
        document.addAuthor("TeamPirates");
        document.addTitle("Global Report");

        Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD);
        Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.UNDERLINE);

        for (User u : SQLConnectMana.getEmployeesFromDb()) {
            JTable jTableTran = new JTable();
            JTable jTableReport = new JTable();

            Chapter chapter = new Chapter(
                    new Paragraph(new Phrase("Employee : " + u.getLogin() + "\n\n", font1)), numEMployees);

            Section section1 = chapter.addSection(new Paragraph(new Phrase("Recent Transactions :\n", font2)),
                    9);

            Section section2 = chapter.addSection(new Paragraph(new Phrase("Reported Companies :\n", font2)),
                    9);

            // Transactions :
            DefaultTableModel modelPDFtrans = new DefaultTableModel();
            modelPDFtrans.setColumnIdentifiers(
                    new String[] { "Name", "Operation", "Quantity", "Price Paid", "Date" });
            for (Transaction t : SQLConnectMana.getTransactions(u.getId())) {
                modelPDFtrans.addRow(new String[] { t.getSymbol(), t.getOperation(),
                        Integer.toString(t.getQuantity()), Double.toString(t.getPricePaid()), t.getDate() });
            }
            jTableTran.setModel(modelPDFtrans);

            PdfPTable pdfTableTrans = new PdfPTable(jTableTran.getColumnCount());

            for (int i = 0; i < jTableTran.getColumnCount(); i++) {
                pdfTableTrans.addCell(jTableTran.getColumnName(i));
            }
            //extracting data from the JTable and inserting it to PdfPTable
            for (int rows = 0; rows < jTableTran.getRowCount(); rows++) {
                for (int cols = 0; cols < jTableTran.getColumnCount(); cols++) {
                    pdfTableTrans.addCell(jTableTran.getModel().getValueAt(rows, cols).toString());

                }
            }
            Paragraph blank = new Paragraph("\n\n");
            section1.add(blank);
            section1.add(pdfTableTrans);

            section1.add(blank);
            //Reported Companies :
            DefaultTableModel modelPDFReported = new DefaultTableModel();
            modelPDFReported.setColumnIdentifiers(
                    new String[] { "Name", "Symbol", "Stock Price ()", "Quantity Bought" });
            for (Company c : SQLConnectMana.getNameOfReported(u.getId())) {
                modelPDFReported.addRow(new String[] { c.getName(), c.getSymbol(),
                        String.valueOf(c.getStockPrice().doubleValue()),
                        Integer.toString(c.getNumberOwned()) });
            }
            jTableReport.setModel(modelPDFReported);
            PdfPTable pdfTableReport = new PdfPTable(jTableReport.getColumnCount());

            for (int i = 0; i < jTableReport.getColumnCount(); i++) {
                pdfTableReport.addCell(jTableReport.getColumnName(i));
            }
            //extracting data from the JTable and inserting it to PdfPTable
            for (int rows = 0; rows < jTableReport.getRowCount(); rows++) {
                for (int cols = 0; cols < jTableReport.getColumnCount(); cols++) {
                    pdfTableReport.addCell(jTableReport.getModel().getValueAt(rows, cols).toString());
                }
            }
            section2.add(blank);
            section2.add(pdfTableReport);
            section2.add(blank);
            //End of doc for a single employee
            document.add(chapter);

            numEMployees++;

        }
        Chapter ban = new Chapter(new Paragraph(new Phrase("Prohibited Companies :\n\n", font1)),
                ++numEMployees);

        com.itextpdf.text.List bannedCompanies = new List(List.ORDERED);
        for (String lii : SQLConnectMana.getBannedCompForAll()) {
            bannedCompanies.add(new com.itextpdf.text.ListItem(lii));
        }
        ban.add(bannedCompanies);
        document.add(ban);
        document.close();
    } catch (DocumentException | FileNotFoundException e) {
        System.err.println("Sorry Problem in pdf.\n" + e);
    }

}

From source file:com.workhub.utils.PDFUtils.java

private static void addContent(Document document, List<ElementModel> models) throws DocumentException {
    for (int i = 0; i < models.size(); i++) {
        ElementModel elementModel = models.get(i);
        Anchor anchor = new Anchor(elementModel.getTitle(), catFont);
        anchor.setName(elementModel.getTitle());
        // Second parameter is the number of the chapter
        Chapter catPart = new Chapter(new Paragraph(anchor), i + 1);

        Paragraph content = new Paragraph();
        catPart.add(content);
        addEmptyLine(content, 2);//from  w  w  w  . j av a  2s.c  om

        switch (elementModel.getType()) {
        case Constants.TYPE_ELEMENT_TEXT:
            content.add(new Paragraph(((TextElementModel) elementModel).getContent(), smallBold));

            break;
        case Constants.TYPE_ELEMENT_LINK:
            content.add(new Paragraph(((LinkElementModel) elementModel).getContent(), smallBold));

            break;
        case Constants.TYPE_ELEMENT_PICTURE:
            Image image1;
            try {
                if (((PictureElementModel) elementModel).getContent() != null) {
                    image1 = Image.getInstance(((PictureElementModel) elementModel).getContent());

                    content.add(image1);
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            break;
        case Constants.TYPE_ELEMENT_FILE:
            content.add(new Paragraph(((FileElementModel) elementModel).getTitle(), smallBold));
            break;

        }

        document.add(catPart);
    }

}

From source file:CTD.planer2.util.ExportToPdf.java

/**
 * In this function, we add the content to the pdf-file
 * //from  w w  w .ja v  a  2 s .  c  o m
 * @param document
 * @throws DocumentException
 */
private static void addContent(Document document) throws DocumentException {

    // Big header
    Chapter catPart = new Chapter(new Paragraph(""), 1);
    catPart.setNumberDepth(0);
    if (roomToExport == null && CPlaner.selDay == null) {
        String[] tmp = FILE.split("\\.");
        catPart.add(new Paragraph(tmp[0], catFont));
    } else if (CPlaner.selDay == null) {
        catPart.add(new Paragraph(roomToExport.toString(), catFont));
    } else {
        catPart.add(new Paragraph(CPlaner.selDay.toString(), catFont));
    }
    addEmptyLine(catPart, 1);

    // Add a table
    if (CPlaner.selDay != null) {
        createDayTable(catPart);
    } else {

        if (roomToExport == null && CPlaner.selDay == null) {
            createTable(catPart);
        } else {
            createTable(catPart, roomToExport);
        }
    }
    document.add(catPart);
}

From source file:CTD.planer2.util.ExportToPdf.java

/**
 * Just a function to add a number empty lines
 * //from w ww.j  a va 2s  . c  o  m
 * @param paragraph
 * @param number
 */
private static void addEmptyLine(Chapter chapter, int number) {
    for (int i = 0; i < number; i++) {
        chapter.add(new Paragraph(" "));
    }
}

From source file:edu.avans.ivh5.shared.util.generateInvoicePDF.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Factuur12", catFont);
    anchor.setName("Factuur");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    // add a list
    //createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, (int) 1);
    catPart.add(paragraph);

    // add a table
    createTable(catPart);//from   ww  w. j  a v  a2s  . co  m

    createTable2(catPart);

    createTable3(catPart);

    createTable4(catPart);

    createTable5(catPart);

    // now add all this to the document
    document.add(catPart);

}