Search in sources :

Example 46 with PdfFont

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

the class C06E10_TOC_OutlinesNames method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    pdf.getCatalog().setPageMode(PdfName.UseOutlines);
    // 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", "uk", 3, 3)).setFont(font).setFontSize(11);
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    String name, line;
    Paragraph p;
    boolean title = true;
    int counter = 0;
    PdfOutline outline = null;
    while ((line = br.readLine()) != null) {
        p = new Paragraph(line);
        p.setKeepTogether(true);
        if (title) {
            name = String.format("title%02d", counter++);
            outline = createOutline(outline, pdf, line, name);
            p.setFont(bold).setFontSize(12).setKeepWithNext(true).setDestination(name);
            title = false;
            document.add(p);
        } else {
            p.setFirstLineIndent(36);
            if (line.isEmpty()) {
                p.setMarginBottom(12);
                title = true;
            } else {
                p.setMarginBottom(0);
            }
            document.add(p);
        }
    }
    // 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) PdfString(com.itextpdf.kernel.pdf.PdfString) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) PdfOutline(com.itextpdf.kernel.pdf.PdfOutline)

Example 47 with PdfFont

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

the class CellProperties 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(2)).useAllAvailableWidth();
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    table.addCell(new Cell().add(new Paragraph("Test 1")).setHeight(50).setDestination("Top"));
    Style style = new Style();
    style.setBackgroundColor(ColorConstants.YELLOW);
    table.addCell(new Cell().setBorder(new DottedBorder(5)).add(new Paragraph("Test 2")).addStyle(style).setRelativePosition(10, 10, 50, 10));
    table.addCell(new Cell().add(new Paragraph("Test 3")).setVerticalAlignment(VerticalAlignment.BOTTOM));
    table.addCell(new Cell().add(ParagraphProperties.getNewParagraphInstance()).setHyphenation(new HyphenationConfig("en", "uk", 3, 3)));
    table.addCell(new Cell().add(new Paragraph("Rotated")).setRotationAngle(Math.PI / 18).setFont(font).setFontSize(8).setFontColor(ColorConstants.RED));
    table.addCell(new Cell().add(new Paragraph("Centered")).setTextAlignment(TextAlignment.CENTER).setAction(PdfAction.createGoTo("Top")));
    table.addCell(new Cell().add(new Paragraph("Test 5")).setBackgroundColor(ColorConstants.BLUE));
    table.addCell(new Cell().add(ParagraphProperties.getNewParagraphInstance()).setBackgroundColor(ColorConstants.RED).setPaddingLeft(20).setPaddingRight(50));
    table.addCell(new Cell().add(new Paragraph("Test 7")).setBackgroundColor(ColorConstants.RED));
    table.addCell(new Cell().add(new Paragraph("Test 8")).setBackgroundColor(ColorConstants.BLUE).setMarginBottom(10));
    table.addCell(new Cell().add(new Paragraph("Test 9")).setBackgroundColor(ColorConstants.BLUE));
    table.addCell(new Cell().add(new Paragraph("Test 10")).setBackgroundColor(ColorConstants.RED));
    table.addCell(new Cell().add(ParagraphProperties.getNewParagraphInstance()).setBackgroundColor(ColorConstants.RED).setMargin(50).setPadding(30));
    table.addCell(new Cell().add(new Paragraph("Test 12")).setBackgroundColor(ColorConstants.BLUE));
    document.add(table);
    SolidBorder border = new SolidBorder(ColorConstants.RED, 2);
    Cell cell = new Cell().add(new Paragraph("Test")).setFixedPosition(100, 400, 350).setBorder(border).setBackgroundColor(ColorConstants.BLUE).setHeight(100).setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(cell);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) Style(com.itextpdf.layout.Style) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) DottedBorder(com.itextpdf.layout.borders.DottedBorder) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) SolidBorder(com.itextpdf.layout.borders.SolidBorder)

Example 48 with PdfFont

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

the class DocumentFontMethods 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);
    Paragraph p;
    p = new Paragraph("Testing font methods");
    document.add(p);
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    document.setFont(font);
    p = new Paragraph("Testing font methods: changed font");
    document.add(p);
    document.setFontSize(18);
    p = new Paragraph("Testing font methods: changed font size");
    document.add(p);
    document.setFontColor(ColorConstants.BLUE);
    p = new Paragraph("Testing font methods: changed color");
    document.add(p);
    document.setBold();
    p = new Paragraph("Testing font methods: to bold");
    document.add(p);
    document.setItalic();
    p = new Paragraph("Testing font methods: to italic");
    document.add(p);
    document.setProperty(Property.BOLD_SIMULATION, false);
    document.setProperty(Property.ITALIC_SIMULATION, false);
    document.setProperty(Property.FONT_COLOR, null);
    p = new Paragraph("Testing font methods: resetting style and color");
    document.add(p);
    document.setLineThrough();
    p = new Paragraph("Testing font methods: line through (default)");
    document.add(p);
    document.setProperty(Property.UNDERLINE, null);
    document.setUnderline();
    p = new Paragraph("Testing font methods: underline (default)");
    document.add(p);
    document.setProperty(Property.UNDERLINE, null);
    document.setUnderline(2, 4);
    document.setUnderline(ColorConstants.BLUE, 5, 0.1f, 2, -0.5f, PdfCanvasConstants.LineCapStyle.ROUND);
    p = new Paragraph("Testing font methods: underline (custom)");
    document.add(p);
    document.setProperty(Property.UNDERLINE, null);
    document.setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
    p = new Paragraph("Testing font methods: change text rendering mode");
    document.add(p);
    document.setStrokeWidth(0.1f);
    document.setStrokeColor(ColorConstants.BLUE);
    p = new Paragraph("Testing font methods: change stroke width and color");
    document.add(p);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 49 with PdfFont

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

the class TableProperties 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);
    Style style = new Style();
    style.setBackgroundColor(ColorConstants.YELLOW);
    document.add(createNewTable().addStyle(style).setDestination("Top").setWidth(300).setHorizontalAlignment(HorizontalAlignment.CENTER)).setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(createNewTable().setBorder(new DottedBorder(5)).setHyphenation(new HyphenationConfig("en", "uk", 3, 3)));
    document.add(createNewTable().setTextAlignment(TextAlignment.CENTER));
    document.add(ListSeparatorProperties.createNewSeparator().setMargin(10).setWidth(300).setKeepWithNext(true));
    document.add(createNewTable().setKeepTogether(true).setWidth(UnitValue.createPercentValue(90)));
    document.add(createNewTable());
    document.add(createNewTable().setRelativePosition(10, 10, 50, 10));
    document.add(createNewTable());
    document.add(new AreaBreak());
    document.add(createNewTable().setFixedPosition(100, 400, 350).setAction(PdfAction.createGoTo("Top")));
    document.add(new AreaBreak());
    document.add(createNewTable().setBackgroundColor(ColorConstants.YELLOW).setMarginBottom(10));
    document.add(createNewTable().setBackgroundColor(ColorConstants.LIGHT_GRAY).setPaddingLeft(20).setPaddingRight(50));
    document.add(createNewTable().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewTable().setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.add(createNewTable().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewTable().setBackgroundColor(ColorConstants.LIGHT_GRAY).setMargin(50).setPadding(30));
    document.add(createNewTable().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewTable().setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) Style(com.itextpdf.layout.Style) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) DottedBorder(com.itextpdf.layout.borders.DottedBorder) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 50 with PdfFont

use of com.itextpdf.kernel.font.PdfFont in project i7j-pdfsweep by itext.

the class PdfCleanUpProcessor method writeNotAppliedTextStateParams.

private void writeNotAppliedTextStateParams(TextRenderInfo text) {
    PdfCanvas canvas = getCanvas();
    CanvasGraphicsState currGs = canvas.getGraphicsState();
    if (currGs.getCharSpacing() != text.getCharSpacing()) {
        canvas.setCharacterSpacing(text.getCharSpacing());
    }
    if (currGs.getWordSpacing() != text.getWordSpacing()) {
        canvas.setWordSpacing(text.getWordSpacing());
    }
    if (currGs.getHorizontalScaling() != text.getHorizontalScaling()) {
        canvas.setHorizontalScaling(text.getHorizontalScaling());
    }
    // not writing leading here, it is processed along with positioning operators
    PdfFont currFont = currGs.getFont();
    if (currFont == null || currFont.getPdfObject() != text.getFont().getPdfObject() || currGs.getFontSize() != text.getFontSize()) {
        canvas.setFontAndSize(text.getFont(), text.getFontSize());
    }
    if (currGs.getTextRenderingMode() != text.getTextRenderMode()) {
        canvas.setTextRenderingMode(text.getTextRenderMode());
    }
    if (currGs.getTextRise() != text.getRise()) {
        canvas.setTextRise(text.getRise());
    }
}
Also used : CanvasGraphicsState(com.itextpdf.kernel.pdf.canvas.CanvasGraphicsState) PdfFont(com.itextpdf.kernel.font.PdfFont) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas)

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