Search in sources :

Example 26 with Table

use of com.itextpdf.layout.element.Table in project i7js-highlevel by itext.

the class C05E08_JekyllHydeTableV1 method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf, PageSize.A4.rotate());
    Table table = new Table(UnitValue.createPercentArray(new float[] { 3, 2, 14, 9, 4, 3 }));
    table.setWidth(UnitValue.createPercentValue(100));
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    List<String> header = resultSet.remove(0);
    for (String field : header) {
        table.addHeaderCell(field);
    }
    Cell cell = new Cell(1, 6).add(new Paragraph("Continued on next page..."));
    table.addFooterCell(cell).setSkipLastFooter(true);
    for (List<String> record : resultSet) {
        for (String field : record) {
            table.addCell(field);
        }
    }
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 27 with Table

use of com.itextpdf.layout.element.Table in project i7js-highlevel by itext.

the class C05E11_JekyllHydeTableV4 method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf, PageSize.A4.rotate());
    Table table = new Table(UnitValue.createPercentArray(new float[] { 3, 32 }));
    table.setWidth(UnitValue.createPercentValue(100));
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    table.addHeaderCell("imdb").addHeaderCell("Information about the movie");
    Cell cell;
    for (List<String> record : resultSet) {
        table.addCell(record.get(0));
        cell = new Cell().add(new Paragraph(record.get(1))).add(new Paragraph(record.get(2))).add(new Paragraph(record.get(3))).add(new Paragraph(record.get(4))).add(new Paragraph(record.get(5)));
        table.addCell(cell);
    }
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 28 with Table

use of com.itextpdf.layout.element.Table in project i7js-highlevel by itext.

the class AlternatingBackgroundTableRenderer method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf, PageSize.A4.rotate());
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    List<String> header = resultSet.remove(0);
    Table table = new Table(UnitValue.createPercentArray(new float[] { 3, 2, 14, 9, 4, 3 }));
    table.setWidth(UnitValue.createPercentValue(100));
    int nRows = resultSet.size();
    table.setNextRenderer(new AlternatingBackgroundTableRenderer(table, new Table.RowRange(0, nRows - 1)));
    for (String field : header) {
        table.addHeaderCell(field);
    }
    for (List<String> record : resultSet) {
        for (String field : record) {
            table.addCell(field);
        }
    }
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 29 with Table

use of com.itextpdf.layout.element.Table in project i7js-highlevel by itext.

the class C05E15_LargeTable method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf);
    Table table = new Table(new float[] { 100, 100, 100 }, true);
    table.addHeaderCell("Table header 1");
    table.addHeaderCell("Table header 2");
    table.addHeaderCell("Table header 3");
    table.addFooterCell("Table footer 1");
    table.addFooterCell("Table footer 2");
    table.addFooterCell("Table footer 3");
    document.add(table);
    for (int i = 0; i < 1000; i++) {
        table.addCell(String.format("Row %s; column 1", i + 1));
        table.addCell(String.format("Row %s; column 2", i + 1));
        table.addCell(String.format("Row %s; column 3", i + 1));
        if (i % 50 == 0) {
            table.flush();
        }
    }
    table.complete();
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 30 with Table

use of com.itextpdf.layout.element.Table in project i7js-highlevel by itext.

the class CellProperties method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf);
    Table table = new Table(UnitValue.createPercentArray(2)).useAllAvailableWidth();
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    table.addCell(new Cell().add(new Paragraph("Test 1")).setHeight(50).setDestination("Top"));
    Style style = new Style();
    style.setBackgroundColor(ColorConstants.YELLOW);
    table.addCell(new Cell().setBorder(new DottedBorder(5)).add(new Paragraph("Test 2")).addStyle(style).setRelativePosition(10, 10, 50, 10));
    table.addCell(new Cell().add(new Paragraph("Test 3")).setVerticalAlignment(VerticalAlignment.BOTTOM));
    table.addCell(new Cell().add(ParagraphProperties.getNewParagraphInstance()).setHyphenation(new HyphenationConfig("en", "uk", 3, 3)));
    table.addCell(new Cell().add(new Paragraph("Rotated")).setRotationAngle(Math.PI / 18).setFont(font).setFontSize(8).setFontColor(ColorConstants.RED));
    table.addCell(new Cell().add(new Paragraph("Centered")).setTextAlignment(TextAlignment.CENTER).setAction(PdfAction.createGoTo("Top")));
    table.addCell(new Cell().add(new Paragraph("Test 5")).setBackgroundColor(ColorConstants.BLUE));
    table.addCell(new Cell().add(ParagraphProperties.getNewParagraphInstance()).setBackgroundColor(ColorConstants.RED).setPaddingLeft(20).setPaddingRight(50));
    table.addCell(new Cell().add(new Paragraph("Test 7")).setBackgroundColor(ColorConstants.RED));
    table.addCell(new Cell().add(new Paragraph("Test 8")).setBackgroundColor(ColorConstants.BLUE).setMarginBottom(10));
    table.addCell(new Cell().add(new Paragraph("Test 9")).setBackgroundColor(ColorConstants.BLUE));
    table.addCell(new Cell().add(new Paragraph("Test 10")).setBackgroundColor(ColorConstants.RED));
    table.addCell(new Cell().add(ParagraphProperties.getNewParagraphInstance()).setBackgroundColor(ColorConstants.RED).setMargin(50).setPadding(30));
    table.addCell(new Cell().add(new Paragraph("Test 12")).setBackgroundColor(ColorConstants.BLUE));
    document.add(table);
    SolidBorder border = new SolidBorder(ColorConstants.RED, 2);
    Cell cell = new Cell().add(new Paragraph("Test")).setFixedPosition(100, 400, 350).setBorder(border).setBackgroundColor(ColorConstants.BLUE).setHeight(100).setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(cell);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) Style(com.itextpdf.layout.Style) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) DottedBorder(com.itextpdf.layout.borders.DottedBorder) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) SolidBorder(com.itextpdf.layout.borders.SolidBorder)

Aggregations

Table (com.itextpdf.layout.element.Table)37 Cell (com.itextpdf.layout.element.Cell)29 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)25 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)25 Document (com.itextpdf.layout.Document)25 Paragraph (com.itextpdf.layout.element.Paragraph)22 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)7 List (java.util.List)7 SolidBorder (com.itextpdf.layout.borders.SolidBorder)3 DashedBorder (com.itextpdf.layout.borders.DashedBorder)2 DottedBorder (com.itextpdf.layout.borders.DottedBorder)2 Image (com.itextpdf.layout.element.Image)2 IOException (java.io.IOException)2 PdfFont (com.itextpdf.kernel.font.PdfFont)1 Rectangle (com.itextpdf.kernel.geom.Rectangle)1 PdfDocumentInfo (com.itextpdf.kernel.pdf.PdfDocumentInfo)1 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)1 Canvas (com.itextpdf.layout.Canvas)1 Style (com.itextpdf.layout.Style)1 SolidBorder (com.itextpdf.layout.border.SolidBorder)1