Search in sources :

Example 26 with PdfFont

use of com.itextpdf.kernel.font.PdfFont in project ComponentManagement by Bac3Phi.

the class InventoriesReportController method addTitlePage.

private void addTitlePage(Document document) throws IOException {
    Paragraph title = new Paragraph("BÁO CÁO HÀNG TỒN");
    // Setting font of the text
    PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);
    title.setFont(font);
    title.setFontSize(22);
    title.setTextAlignment(TextAlignment.CENTER);
    document.add(title);
}
Also used : PdfFont(com.itextpdf.kernel.font.PdfFont) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 27 with PdfFont

use of com.itextpdf.kernel.font.PdfFont in project ComponentManagement by Bac3Phi.

the class InventoriesReportController method addHeader.

private void addHeader(String strheader, Document document) throws IOException {
    Paragraph header = new Paragraph(strheader);
    // Setting font of the text
    PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);
    header.setFont(font);
    header.setFontSize(14);
    header.setTextAlignment(TextAlignment.LEFT);
    document.add(header);
}
Also used : PdfFont(com.itextpdf.kernel.font.PdfFont) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 28 with PdfFont

use of com.itextpdf.kernel.font.PdfFont in project spring-learning by moon-zhou.

the class Demo002 method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF writer
    PdfWriter writer = new PdfWriter(dest);
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);
    // Initialize document
    Document document = new Document(pdf);
    // Create a PdfFont
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    // Add a Paragraph
    document.add(new Paragraph("iText is:").setFont(font));
    // Create a List
    List list = new List().setSymbolIndent(12).setListSymbol("\u2022").setFont(font);
    // Add ListItem objects
    list.add(new ListItem("Never gonna give you up")).add(new ListItem("Never gonna let you down")).add(new ListItem("Never gonna run around and desert you")).add(new ListItem("Never gonna make you cry")).add(new ListItem("Never gonna say goodbye")).add(new ListItem("Never gonna tell a lie and hurt you"));
    // Add the list
    document.add(list);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) List(com.itextpdf.layout.element.List) ListItem(com.itextpdf.layout.element.ListItem) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 29 with PdfFont

use of com.itextpdf.kernel.font.PdfFont in project i7js-highlevel by itext.

the class C02E07_JekyllHydeV3 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);
    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);
    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();
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) BufferedReader(java.io.BufferedReader) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) FileReader(java.io.FileReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 30 with PdfFont

use of com.itextpdf.kernel.font.PdfFont in project i7js-highlevel by itext.

the class C02E09_JekyllHydeV5 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 nextPage = new AreaBreak(AreaBreakType.NEXT_PAGE);
    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(nextPage);
            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)

Aggregations

PdfFont (com.itextpdf.kernel.font.PdfFont)51 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)45 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)45 Paragraph (com.itextpdf.layout.element.Paragraph)45 Document (com.itextpdf.layout.Document)39 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)29 BufferedReader (java.io.BufferedReader)24 FileReader (java.io.FileReader)24 AreaBreak (com.itextpdf.layout.element.AreaBreak)17 Rectangle (com.itextpdf.kernel.geom.Rectangle)12 Text (com.itextpdf.layout.element.Text)10 PdfPage (com.itextpdf.kernel.pdf.PdfPage)8 DottedLine (com.itextpdf.kernel.pdf.canvas.draw.DottedLine)8 Div (com.itextpdf.layout.element.Div)8 ArrayList (java.util.ArrayList)8 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)7 Tab (com.itextpdf.layout.element.Tab)7 TabStop (com.itextpdf.layout.element.TabStop)7 Canvas (com.itextpdf.layout.Canvas)6 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)6