Search in sources :

Example 1 with Text

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

the class C04E08_CustomListSymbols method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    PageSize pagesize = PageSize.A6.rotate();
    Document document = new Document(pdf, pagesize);
    // Set column parameters
    float offSet = 36;
    float gutter = 23;
    float columnWidth = (pagesize.getWidth() - offSet * 2) / 2 - gutter;
    float columnHeight = pagesize.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));
    List list = new List();
    list.setListSymbol("\u2022");
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List();
    PdfFont font = PdfFontFactory.createFont(StandardFonts.ZAPFDINGBATS);
    list.setListSymbol(new Text("*").setFont(font).setFontColor(ColorConstants.ORANGE));
    list.setSymbolIndent(10);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    Image info = new Image(ImageDataFactory.create(INFO));
    info.scaleAbsolute(12, 12);
    list = new List().setSymbolIndent(3);
    list.setListSymbol(info);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List();
    list.setListSymbol(ListNumberingType.ENGLISH_LOWER);
    list.setPostSymbolText("- ");
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.DECIMAL);
    list.setPreSymbolText("Part ");
    list.setPostSymbolText(": ");
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.DECIMAL);
    list.setItemStartIndex(5);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ROMAN_LOWER);
    list.setListSymbolAlignment(ListSymbolAlignment.LEFT);
    for (int i = 0; i < 6; i++) {
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
    }
    document.add(list);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PageSize(com.itextpdf.kernel.geom.PageSize) Rectangle(com.itextpdf.kernel.geom.Rectangle) Text(com.itextpdf.layout.element.Text) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfFont(com.itextpdf.kernel.font.PdfFont) List(com.itextpdf.layout.element.List)

Example 2 with Text

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

the class C03E07_TextExample method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Text t1 = new Text("The Strange Case of ");
    Text t2 = new Text("Dr. Jekyll").setTextRise(5);
    Text t3 = new Text(" and ").setHorizontalScaling(2);
    Text t4 = new Text("Mr. Hyde").setSkew(10, 45);
    document.add(new Paragraph(t1).add(t2).add(t3).add(t4));
    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 3 with Text

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

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

Example 5 with Text

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

the class C01E10_ReusingStyles method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Style normal = new Style();
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    normal.setFont(font).setFontSize(14);
    Style code = new Style();
    PdfFont monospace = PdfFontFactory.createFont(StandardFonts.COURIER);
    code.setFont(monospace).setFontColor(ColorConstants.RED).setBackgroundColor(ColorConstants.LIGHT_GRAY);
    Paragraph p = new Paragraph();
    p.add(new Text("The Strange Case of ").addStyle(normal));
    p.add(new Text("Dr. Jekyll").addStyle(code));
    p.add(new Text(" and ").addStyle(normal));
    p.add(new Text("Mr. Hyde").addStyle(code));
    p.add(new Text(".").addStyle(normal));
    document.add(p);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) Style(com.itextpdf.layout.Style) 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)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