Search in sources :

Example 36 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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 37 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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 38 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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 39 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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 40 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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

Paragraph (com.itextpdf.layout.element.Paragraph)128 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)109 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)109 Document (com.itextpdf.layout.Document)103 PdfFont (com.itextpdf.kernel.font.PdfFont)45 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)29 BufferedReader (java.io.BufferedReader)26 FileReader (java.io.FileReader)26 Table (com.itextpdf.layout.element.Table)22 Cell (com.itextpdf.layout.element.Cell)21 AreaBreak (com.itextpdf.layout.element.AreaBreak)20 Image (com.itextpdf.layout.element.Image)20 List (java.util.List)17 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)16 Text (com.itextpdf.layout.element.Text)16 Rectangle (com.itextpdf.kernel.geom.Rectangle)15 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)14 Tab (com.itextpdf.layout.element.Tab)13 ArrayList (java.util.ArrayList)13 TabStop (com.itextpdf.layout.element.TabStop)12