Search in sources :

Example 6 with Text

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

the class C02E12_JekyllHydeV8 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, false);
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
    document.setTextAlignment(TextAlignment.JUSTIFIED).setHyphenation(new HyphenationConfig("en", null, 3, 3)).setFont(font).setFontSize(11);
    Text totalPages = new Text("This document has {totalpages} pages.");
    IRenderer renderer = new TextRenderer(totalPages);
    totalPages.setNextRenderer(renderer);
    document.add(new Paragraph(totalPages));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    String line;
    Paragraph p;
    boolean title = true;
    while ((line = br.readLine()) != null) {
        p = new Paragraph(line);
        p.setKeepTogether(true);
        if (title) {
            p.setFont(bold).setFontSize(12);
            title = false;
        } else {
            p.setFirstLineIndent(36);
        }
        if (line.isEmpty()) {
            p.setMarginBottom(12);
            title = true;
        } else {
            p.setMarginBottom(0);
        }
        document.add(p);
    }
    br.close();
    String total = renderer.toString().replace("{totalpages}", String.valueOf(pdf.getNumberOfPages()));
    ((TextRenderer) renderer).setText(total);
    ((Text) renderer.getModelElement()).setNextRenderer(renderer);
    document.relayout();
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) 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) IRenderer(com.itextpdf.layout.renderer.IRenderer) PdfFont(com.itextpdf.kernel.font.PdfFont) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) TextRenderer(com.itextpdf.layout.renderer.TextRenderer)

Example 7 with Text

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

the class C01E02_Text_Paragraph_Cardo2 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 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) 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 8 with Text

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

the class C01E07_FontSize 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 ").setFontSize(12);
    Text title2 = new Text("Dr. Jekyll and Mr. Hyde").setFontSize(16);
    Text author = new Text("Robert Louis Stevenson");
    Paragraph p = new Paragraph().setFontSize(8).add(title1).add(title2).add(" by ").add(author);
    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)

Example 9 with Text

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

the class C01E08_BoldItalic 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 ").setItalic();
    Text title2 = new Text("Dr. Jekyll and Mr. Hyde").setBold();
    Text author = new Text("Robert Louis Stevenson").setItalic().setBold();
    Paragraph p = new Paragraph().add(title1).add(title2).add(" by ").add(author);
    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)

Example 10 with Text

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

the class C02E02_CanvasCut method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    PdfPage page = pdf.addNewPage();
    PdfCanvas pdfCanvas = new PdfCanvas(page);
    Rectangle rectangle = new Rectangle(36, 750, 100, 50);
    pdfCanvas.rectangle(rectangle);
    pdfCanvas.stroke();
    Canvas canvas = new Canvas(pdfCanvas, rectangle);
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    PdfFont bold = PdfFontFactory.createFont(StandardFonts.TIMES_BOLD);
    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().add(title).add(" by ").add(author);
    canvas.add(p);
    canvas.close();
    // Close document
    pdf.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Canvas(com.itextpdf.layout.Canvas) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfFont(com.itextpdf.kernel.font.PdfFont) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) Text(com.itextpdf.layout.element.Text) PdfPage(com.itextpdf.kernel.pdf.PdfPage) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)17 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)17 Text (com.itextpdf.layout.element.Text)17 Paragraph (com.itextpdf.layout.element.Paragraph)16 Document (com.itextpdf.layout.Document)13 PdfFont (com.itextpdf.kernel.font.PdfFont)10 Rectangle (com.itextpdf.kernel.geom.Rectangle)5 PdfPage (com.itextpdf.kernel.pdf.PdfPage)4 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)4 Canvas (com.itextpdf.layout.Canvas)4 Style (com.itextpdf.layout.Style)2 SolidBorder (com.itextpdf.layout.borders.SolidBorder)2 FontProgram (com.itextpdf.io.font.FontProgram)1 PageSize (com.itextpdf.kernel.geom.PageSize)1 PdfAction (com.itextpdf.kernel.pdf.action.PdfAction)1 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)1 Image (com.itextpdf.layout.element.Image)1 Link (com.itextpdf.layout.element.Link)1 List (com.itextpdf.layout.element.List)1 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)1