Search in sources :

Example 11 with Cell

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

the class C05E02_ColumnWidths1 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[] { 200, 100, 100 });
    table.addCell(new Cell(1, 3).add(new Paragraph("Cell with colspan 3")));
    table.addCell(new Cell(2, 1).add(new Paragraph("Cell with rowspan 2")));
    table.addCell("row 1; cell 1");
    table.addCell("row 1; cell 2");
    table.addCell("row 2; cell 1");
    table.addCell("row 2; cell 2");
    document.add(table);
    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) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 12 with Cell

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

the class C05E02_ColumnWidths3 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(new float[] { 2, 1, 1 }));
    table.setWidth(450);
    table.setHorizontalAlignment(HorizontalAlignment.CENTER);
    table.addCell(new Cell(1, 3).add(new Paragraph("Cell with colspan 3")));
    table.addCell(new Cell(2, 1).add(new Paragraph("Cell with rowspan 2")));
    table.addCell("row 1; cell 1");
    table.addCell("row 1; cell 2");
    table.addCell("row 2; cell 1");
    table.addCell("row 2; cell 2");
    document.add(table);
    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) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 13 with Cell

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

the class C05E04_ColumnHeights method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Paragraph p = new Paragraph("The Strange Case of\nDr. Jekyll\nand\nMr. Hyde").setBorder(new DashedBorder(0.3f));
    // Initialize document
    Document document = new Document(pdf);
    Table table = new Table(UnitValue.createPercentArray(new float[] { 1 }));
    table.setWidth(UnitValue.createPercentValue(100));
    table.addCell(p);
    Cell cell = new Cell().setHeight(45).add(p);
    table.addCell(cell);
    cell = new Cell().setMinHeight(45).add(p);
    table.addCell(cell);
    cell = new Cell().setMinHeight(135).add(p);
    table.addCell(cell);
    cell = new Cell().setMaxHeight(45).add(p);
    table.addCell(cell);
    cell = new Cell().setMaxHeight(135).add(p);
    table.addCell(cell);
    cell = new Cell().add(p).setRotationAngle(Math.PI / 6);
    table.addCell(cell);
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) DashedBorder(com.itextpdf.layout.borders.DashedBorder) 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 14 with Cell

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

the class C05E09_JekyllHydeTableV2 method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    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);
    }
    for (List<String> record : resultSet) {
        for (String field : record) {
            table.addCell(field);
        }
    }
    Table outerTable = new Table(new float[] { 1 }).addHeaderCell("Continued from previous page:").setSkipFirstHeader(true).addCell(new Cell().add(table).setPadding(0));
    document.add(outerTable);
    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)

Example 15 with Cell

use of com.itextpdf.layout.element.Cell in project digilib by robcast.

the class PDFTitlePage method createPage.

/**
 * Add the the title page to the PDF Document.
 *
 * @return
 */
public Document createPage(Document content) {
    /*
         * header with logo
         */
    Table headerBlock = new Table(UnitValue.createPercentArray(new float[] { 20, 80 }));
    Image logo = getLogo();
    if (logo != null) {
        logo.setWidth(UnitValue.createPercentValue(100));
        headerBlock.addCell(new Cell().add(logo).setBorderRight(null));
    }
    String headerText = getHeaderTitle();
    if (!headerText.isEmpty()) {
        Cell textCell = new Cell().setBorderLeft(null).setPaddingLeft(12).add(new Paragraph(headerText).setBold());
        String headerSubtext = getHeaderSubtitle();
        if (headerSubtext != null) {
            textCell.add(new Paragraph(headerSubtext));
        }
        headerBlock.addCell(textCell);
    }
    content.add(headerBlock.setMarginBottom(24));
    String reference = getReference();
    if (!reference.isEmpty()) {
        /*
             * full reference
             */
        content.add(new Paragraph(reference));
    } else {
        /*
             * author
             */
        String author = getAuthor();
        if (!author.isEmpty()) {
            content.add(new Paragraph(author).setTextAlignment(TextAlignment.CENTER));
        }
        /*
             * title
             */
        String title = getTitle();
        if (!title.isEmpty()) {
            content.add(new Paragraph(title).setTextAlignment(TextAlignment.CENTER));
        }
        /*
             * date
             */
        String date = getDate();
        if (!date.isEmpty()) {
            content.add(new Paragraph(date).setTextAlignment(TextAlignment.CENTER));
        }
    }
    /*
         * page numbers
         */
    content.add(new Paragraph(getPages()).setTextAlignment(TextAlignment.CENTER));
    /*
         * URL
         */
    try {
        content.add(new Paragraph().setTextAlignment(TextAlignment.CENTER).setFont(PdfFontFactory.createFont(StandardFonts.COURIER)).setFontSize(10).add(new Link(getUrl(), PdfAction.createURI(getUrl()))).setFixedPosition(24, 24, UnitValue.createPercentValue(98)));
    } catch (IOException e) {
        logger.error("{}", e);
    }
    return content;
}
Also used : Table(com.itextpdf.layout.element.Table) IOException(java.io.IOException) Image(com.itextpdf.layout.element.Image) Cell(com.itextpdf.layout.element.Cell) Link(com.itextpdf.layout.element.Link) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

Cell (com.itextpdf.layout.element.Cell)34 Table (com.itextpdf.layout.element.Table)29 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)21 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)21 Document (com.itextpdf.layout.Document)21 Paragraph (com.itextpdf.layout.element.Paragraph)21 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)6 List (java.util.List)6 Image (com.itextpdf.layout.element.Image)4 DottedBorder (com.itextpdf.layout.borders.DottedBorder)3 SolidBorder (com.itextpdf.layout.borders.SolidBorder)3 IOException (java.io.IOException)3 DashedBorder (com.itextpdf.layout.borders.DashedBorder)2 File (java.io.File)2 BarcodeEAN (com.itextpdf.barcodes.BarcodeEAN)1 ImageData (com.itextpdf.io.image.ImageData)1 PdfFont (com.itextpdf.kernel.font.PdfFont)1 Style (com.itextpdf.layout.Style)1 AreaBreak (com.itextpdf.layout.element.AreaBreak)1 Link (com.itextpdf.layout.element.Link)1