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.imipgroup.hieuvt.pdf.PdfUtils.java

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

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

    PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/* www. jav  a2  s . co m*/

    c1 = new PdfPCell(new Phrase("Table Header 2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

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

    table.addCell("1.0");
    table.addCell("1.1");
    table.addCell("1.2");
    table.addCell("2.1");
    table.addCell("2.2");
    table.addCell("2.3");

    subCatPart.add(table);

}

From source file:com.leenmeij.app.utils.CreatePdf.java

/**
 * Create the content page of the PDF file
 * @param document/*from  ww  w  .j  a  v a2  s. c  o m*/
 * @param invoice
 * @throws DocumentException
 */
private static void contentPage(Document document, Invoice invoice) throws DocumentException {
    // Get the customer information
    User user = new User();
    user = user.getById(invoice.getUser_id());

    // Create a chapter
    Chapter catPart = new Chapter(new Paragraph("LeenMeij Factuur gegevens", catFont), 1);

    // Add a sub paragraph
    Paragraph subParagraph = new Paragraph("Klantgegevens", subFont);
    Section subCatPart = catPart.addSection(subParagraph);

    // Set the user information
    subCatPart.add(new Paragraph("Naam: " + user.getFirstName() + " " + user.getLastName()));
    subCatPart.add(new Paragraph("Adres: " + user.getAddressLineOne() + " " + user.getAddressLineTwo()));
    subCatPart.add(new Paragraph("Woonplaats:" + user.getCity()));
    subCatPart.add(new Paragraph("Land: " + user.getCountry()));

    // Add another subparagraph
    subParagraph = new Paragraph("Huurgegevens:", subFont);
    subCatPart = catPart.addSection(subParagraph);
    // Format the date for showing purposes
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/YYYY");
    // Add the dates
    subCatPart.add(new Paragraph("Startdatum: " + format.format(invoice.getStartdate())));
    subCatPart.add(new Paragraph("Einddatum: " + format.format(invoice.getEnddate())));

    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart, invoice);

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

From source file:com.leenmeij.app.utils.CreatePdf.java

/**
 * Create a table with the invoice data/* w w w  .ja  v  a 2s .c o m*/
 * @param subCatPart
 * @param invoice
 * @throws BadElementException
 */
private static void createTable(Section subCatPart, Invoice invoice) throws BadElementException {
    PdfPTable table = new PdfPTable(2);

    // Get the vehicle information
    Vehicle vehicle = new Vehicle();
    vehicle = vehicle.getById(invoice.getVehicle_id());

    // Add the vehicle information
    table.addCell("Merk");
    table.addCell(vehicle.getBrand());

    table.addCell("Model");
    table.addCell(vehicle.getModel());

    table.addCell("Kenteken");
    table.addCell(vehicle.getLicenseplate());

    table.addCell("Prijs per dag");
    // Set the format for the doubless
    DecimalFormat format = new DecimalFormat("#.00");
    table.addCell(" " + format.format(vehicle.getHourlyrate() * 24));

    //Add the chosen vehicleoptions
    VehicleOption vehicleOption = new VehicleOption();
    for (Integer o : vehicleOption.all(invoice.getReservation_id())) {
        int day = 24 * 60 * 60 * 1000;
        // Calculate the number of days
        long days = Math.abs((invoice.getStartdate().getTime() - invoice.getEnddate().getTime()) / day);
        // Set the name of the option
        table.addCell(vehicleOption.getByID(o).getName());
        // Set the price of the option
        table.addCell(" " + format.format(vehicleOption.getByID(o).getPrice() * 24 * days));
    }

    // Set the prices
    table.addCell("Prijs");
    table.addCell(" " + format.format(invoice.getPrice()));

    table.addCell("BTW");
    table.addCell(" " + format.format((invoice.getPrice() / 100) * 21));

    table.addCell("Totaalprijs:");
    table.addCell(" " + format.format(invoice.getTotal()));

    // Add the table to the document
    subCatPart.add(table);

}

From source file:com.nerdcastle.nazmul.filetest.MainActivity.java

private static void createTable(Section subCatPart) throws BadElementException {
    ArrayList<String> a = new ArrayList<>();
    a.add("1");//  w ww .  j av  a 2 s  . c  o  m
    a.add("2");
    a.add("3");
    ArrayList<String> b = new ArrayList<>();
    b.add("4");
    b.add("5");
    b.add("6");
    ArrayList<String> c = new ArrayList<>();
    c.add("7");
    c.add("8");
    c.add("9");
    PdfPTable table = new PdfPTable(3);

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

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

    c1 = new PdfPCell(new Phrase("Table Header 2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Table Header 3"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);
    for (int i = 0; i < a.size(); i++) {
        table.addCell(a.get(i));
        table.addCell(b.get(i));
        table.addCell(c.get(i));
    }

    /* table.addCell("1.0");
     table.addCell("1.1");
     table.addCell("1.2");
     table.addCell("2.1");
     table.addCell("2.2");
     table.addCell("2.3");*/

    subCatPart.add(table);

}

From source file:com.pdg.ticket.utils.FirstPdf.java

private static void addContent(Document document) throws DocumentException {
    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);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);/*from  w  w  w.  j  av  a2  s  .  c o  m*/
    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.pdg.ticket.utils.FirstPdf.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("Table Header 1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.RED);
    table.addCell(c1);/*from www  .j av a 2s. c  o m*/

    c1 = new PdfPCell(new Phrase("Table Header 2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

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

    table.addCell("1.0");
    table.addCell("1.1");
    table.addCell("1.2");
    table.addCell("2.1");
    table.addCell("2.2");
    table.addCell("2.3");

    subCatPart.add(table);

}

From source file:com.shashi.itext.write.FirstPdf.java

private static void addContent(Document document) throws DocumentException {

    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);/*from  w  ww  .  j  a  v  a 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
    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.util.Imprimir.java

public static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Capitulo Primeiro", catFont);
    anchor.setName("Capitulo Primeiro");

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

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

    subPara = new Paragraph("Subcategoria 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragrafo 1"));
    subCatPart.add(new Paragraph("Paragrafo 2"));
    subCatPart.add(new Paragraph("Paragrafo 3"));

    // add a list
    createList(subCatPart);/*w  w  w  . j  a  v a  2 s  .c  o  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("Capitulo Segundo", catFont);
    anchor.setName("Capitulo Segundo");

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

    subPara = new Paragraph("Subcategoria", 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.zaptech.pdfdemo.MainActivity.java

private void addContent(Document document) {
    try {//from  w  w w  . j  a va  2s. c o  m
        Anchor anchor = new Anchor("First Chapter", catFont);
        anchor.setName("First Chapter");
        Chapter chapter = new Chapter(new Paragraph(anchor), 1);
        Paragraph paragraph = new Paragraph("Subcategory 1", subFont);
        Section section = chapter.addSection(paragraph);
        section.add(new Paragraph("Hello"));
        paragraph = new Paragraph("Subcategory 2", subFont);
        section = chapter.addSection(paragraph);
        section.add(new Paragraph("Paragraph 1"));
        section.add(new Paragraph("Paragraph 2"));
        section.add(new Paragraph("Paragraph 3"));
        createList(section);
        Paragraph paragraph1 = new Paragraph();
        addEmptyLine(paragraph1, 5);
        section.add(paragraph1);
        document.add(chapter);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.zaptech.pdfdemo.MainActivity.java

private void createList(Section section) {
    List list = new List(true, false, 10);
    list.add(new ListItem("First point"));
    list.add(new ListItem("Second point"));
    list.add(new ListItem("Third point"));
    section.add(list);
}