Search in sources :

Example 41 with PdfWriter

use of com.itextpdf.kernel.pdf.PdfWriter 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 42 with PdfWriter

use of com.itextpdf.kernel.pdf.PdfWriter 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 43 with PdfWriter

use of com.itextpdf.kernel.pdf.PdfWriter in project i7js-highlevel by itext.

the class C02E08_JekyllHydeV4 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);
    // Set column parameters
    float offSet = 36;
    float gutter = 23;
    float columnWidth = (PageSize.A4.getWidth() - offSet * 2) / 2 - gutter;
    float columnHeight = PageSize.A4.getHeight() - offSet * 2;
    // Define column areas
    Rectangle[] columns = { new Rectangle(offSet, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth + gutter, offSet, columnWidth, columnHeight) };
    document.setRenderer(new ColumnDocumentRenderer(document, columns));
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
    document.setTextAlignment(TextAlignment.JUSTIFIED).setFont(font).setHyphenation(new HyphenationConfig("en", null, 3, 3));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    String line;
    Paragraph p;
    boolean title = true;
    AreaBreak nextArea = new AreaBreak(AreaBreakType.NEXT_AREA);
    while ((line = br.readLine()) != null) {
        p = new Paragraph(line);
        if (title) {
            p.setFont(bold).setFontSize(12);
            title = false;
        } else {
            p.setFirstLineIndent(36);
        }
        if (line.isEmpty()) {
            document.add(nextArea);
            title = true;
        }
        document.add(p);
    }
    br.close();
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Rectangle(com.itextpdf.kernel.geom.Rectangle) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfFont(com.itextpdf.kernel.font.PdfFont) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 44 with PdfWriter

use of com.itextpdf.kernel.pdf.PdfWriter in project i7js-highlevel by itext.

the class C01E03_Text_Paragraph_NoCardo 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);
    // Add content: the fonts aren't embedded! Don't do this!
    PdfFont font = PdfFontFactory.createFont(REGULAR, PdfEncodings.WINANSI, EmbeddingStrategy.PREFER_NOT_EMBEDDED);
    PdfFont bold = PdfFontFactory.createFont(BOLD, PdfEncodings.WINANSI, EmbeddingStrategy.PREFER_NOT_EMBEDDED);
    PdfFont italic = PdfFontFactory.createFont(ITALIC, PdfEncodings.WINANSI, EmbeddingStrategy.PREFER_NOT_EMBEDDED);
    Text title = new Text("The Strange Case of Dr. Jekyll and Mr. Hyde").setFont(bold);
    Text author = new Text("Robert Louis Stevenson").setFont(font);
    Paragraph p = new Paragraph().setFont(italic).add(title).add(" by ").add(author);
    document.add(p);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) Text(com.itextpdf.layout.element.Text) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 45 with PdfWriter

use of com.itextpdf.kernel.pdf.PdfWriter in project i7js-highlevel by itext.

the class C01E09_ColorRendering 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);
    // Add content
    Text title1 = new Text("The Strange Case of ").setFontColor(ColorConstants.BLUE);
    Text title2 = new Text("Dr. Jekyll").setStrokeColor(ColorConstants.GREEN).setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE);
    Text title3 = new Text(" and ");
    Text title4 = new Text("Mr. Hyde").setStrokeColor(ColorConstants.RED).setStrokeWidth(0.5f).setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
    Paragraph p = new Paragraph().setFontSize(24).add(title1).add(title2).add(title3).add(title4);
    document.add(p);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Text(com.itextpdf.layout.element.Text) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)194 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)194 Document (com.itextpdf.layout.Document)130 Paragraph (com.itextpdf.layout.element.Paragraph)110 PdfReader (com.itextpdf.kernel.pdf.PdfReader)56 PdfFont (com.itextpdf.kernel.font.PdfFont)45 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)39 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)39 Test (org.junit.Test)39 Rectangle (com.itextpdf.kernel.geom.Rectangle)37 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)32 BufferedReader (java.io.BufferedReader)26 FileReader (java.io.FileReader)26 AreaBreak (com.itextpdf.layout.element.AreaBreak)25 Image (com.itextpdf.layout.element.Image)25 Table (com.itextpdf.layout.element.Table)25 ArrayList (java.util.ArrayList)24 List (java.util.List)22 Cell (com.itextpdf.layout.element.Cell)21 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)20