Example usage for com.itextpdf.text Section add

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

Introduction

In this page you can find the example usage for com.itextpdf.text Section 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:com.debashubham.dumpy.SimpleCalcActivity.java

private void createTable(Section subCatPart) throws BadElementException {
    PdfPTable entry_table = new PdfPTable(7);
    entry_table.setWidthPercentage(100);
    PdfPCell id = new PdfPCell(new Phrase("Station Point"));
    id.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell bs = new PdfPCell(new Phrase("BS"));
    bs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell is = new PdfPCell(new Phrase("IS"));
    is.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell fs = new PdfPCell(new Phrase("FS"));
    fs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell hi = new PdfPCell(new Phrase("HI"));
    hi.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell rl = new PdfPCell(new Phrase("RL"));
    rl.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell remarks = new PdfPCell(new Phrase("REMARKS"));
    remarks.setHorizontalAlignment(Element.ALIGN_CENTER);
    entry_table.addCell(id);/*from  w w  w .  j a v  a 2  s.co m*/
    entry_table.addCell(bs);
    entry_table.addCell(is);
    entry_table.addCell(fs);
    entry_table.addCell(hi);
    entry_table.addCell(rl);
    entry_table.addCell(remarks);
    entry_table.setHeaderRows(1);
    int largest = rl_list.size();

    Log.e("Total RL:", String.valueOf(largest));
    double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0;

    for (int i = 1; i <= largest; i++) {

        entry_table.addCell(String.valueOf(i));

        if (i == 1)
            first_rl = rl_list.get(i);
        if (i == largest)
            last_rl = rl_list.get(i);

        if (bs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(bs_list.get(i)));
            total_bs += bs_list.get(i);
            Log.e("TABLE:", "BS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "BS not entered");
        }
        if (is_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(is_list.get(i)));
            Log.e("TABLE:", "IS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "IS not entered");
        }
        if (fs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(fs_list.get(i)));
            total_fs += fs_list.get(i);
            Log.e("TABLE:", "FS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "FS not entered");
        }
        if (hi_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(hi_list.get(i)));
            Log.e("TABLE:", "HI");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "HI not entered");
        }
        if (rl_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(rl_list.get(i)));
            Log.e("TABLE:", "RL");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "RL not entered");
        }
        if (remarks_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(remarks_list.get(i)));
            Log.e("TABLE:", "REMARKS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "REMARKS not entered");
        }
    }
    subCatPart.add(entry_table);
    Log.e("Total BS:", String.valueOf(total_bs));
    Log.e("Total FS:", String.valueOf(total_fs));
    Log.e("First RL:", String.valueOf(first_rl));
    Log.e("Last RL:", String.valueOf(last_rl));
    Paragraph check_para = new Paragraph("Arithmetic Check:", subFont);
    addEmptyLine(check_para, 2);
    check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL");
    addEmptyLine(check_para, 1);
    double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0;
    double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0;
    boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false;
    check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff));
    addEmptyLine(check_para, 1);
    if (checktrue) {
        check_para.setSpacingBefore(20);
        check_para.add("OK");
    } else {
        check_para.setSpacingBefore(20);
        check_para.add("Check Fail!");
    }
    addEmptyLine(check_para, 1);
    check_para.add("_______________________________________________________");
    subCatPart.add(check_para);
    Paragraph legend_para = new Paragraph("LEGEND:", subFont);
    addEmptyLine(legend_para, 2);
    legend_para.add("BS : Back Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("IS : Intermediate Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("FS : Fore Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("HI : Height of Instrument");
    addEmptyLine(legend_para, 1);
    legend_para.add("RL : Reduced Level");
    subCatPart.add(legend_para);
}

From source file:com.equiworx.util.Main.java

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

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

    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);/*from   w w w .ja  va 2  s . co m*/
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

    // 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:com.equiworx.util.Main.java

private static void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Job Name:"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/*from   ww w. j a v  a 2  s.  c o m*/

    c1 = new PdfPCell(new Phrase("Test 001"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("Date:");
    table.addCell("1.1");
    table.addCell("");
    table.addCell("Labor Rate:");
    table.addCell("2.2");
    table.addCell("");
    table.addCell("Labor Cost:");
    table.addCell("3.2");
    table.addCell("3.3");

    subCatPart.add(table);

}

From source file:com.example.drivequickstart.PDFActivity.java

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

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

    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"));
    try {/*from ww  w.j a  v a  2s . c om*/
        Drawable d = PDFActivity.this.getResources().getDrawable(R.drawable.ic_launcher);

        Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        Image image = Image.getInstance(stream.toByteArray());

        subCatPart.add(image);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Add a list
    createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

    // 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:com.example.drivequickstart.PDFActivity.java

private void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Job Name:"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/*from  w  ww  .  j a v  a 2s . c  om*/

    c1 = new PdfPCell(new Phrase("Test 001"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("Date:");
    table.addCell("1.1");
    table.addCell("");
    table.addCell("Labor Rate:");
    table.addCell("2.2");
    table.addCell("");
    table.addCell("Labor Cost:");
    table.addCell("3.2");
    table.addCell("3.3");

    subCatPart.add(table);

}

From source file:com.example.pdfcreate.MainActivity.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("ESTIMATING APP");
    anchor.setName("ESTIMATING APP");

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

    Paragraph subPara = new Paragraph("Subcategory 1");
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello This Is PDF yeeee"));

    subPara = new Paragraph("Subcategory 2");
    subCatPart = catPart.addSection(subPara);

    subCatPart.add(new Paragraph(str1));
    subCatPart.add(new Paragraph(str2));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a list
    createList(subCatPart);//from   w ww . ja v a  2  s  .  c  om
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

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

    // Next section
    anchor = new Anchor("Second Chapter");
    anchor.setName("Second Chapter");

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

    subPara = new Paragraph("Subcategory");
    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: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";
    }//  w  ww .  j  a v  a 2s  .co  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.horizzon.inventerium.ExportPdf.java

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

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

    Paragraph subPara = new Paragraph("Subcategory 1");
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2");
    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);/*from  ww  w .ja  v  a  2 s  . co m*/
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart);

    // 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:com.horizzon.inventerium.ExportPdf.java

private static void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Buy Date"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/* ww w .j  av  a2 s  .  c  o  m*/

    c1 = new PdfPCell(new Phrase("Shopkeeper Name"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Quantity"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Amount"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Profit"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Payment Status"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    for (int i = 0; i < transaction_list_export.size(); i++) {

        HashMap<String, String> transactionlist = new HashMap<String, String>();
        transactionlist = transaction_list_export.get(i);

        table.addCell("" + transactionlist.get(T_DATE));

        int pos = find_Shopkeeper_id(transactionlist.get(USER_ID), shopkeeper_id_export);
        table.addCell("" + shopkeeper_name_export.get(pos));
        table.addCell(transactionlist.get(T_QTY));

        int am = Integer.parseInt(transactionlist.get(T_UNIT_PRICE))
                * Integer.parseInt(transactionlist.get(T_QTY));
        table.addCell("" + am);

        table.addCell("" + Integer.parseInt(transactionlist.get(T_UNIT_PRICE)) / 2);

        table.addCell(transactionlist.get(T_PAYMENT_STATUS));

    }
    subCatPart.add(table);

}

From source file:com.imipgroup.hieuvt.pdf.PdfUtils.java

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

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

    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);// w  ww  .j  ava  2 s.  com
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);
    // add a table
    createTable(subCatPart);

    // now add all this to the document
    try {
        document.add(catPart);
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    // 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
    try {
        document.add(catPart);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}