Search in sources :

Example 1 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle 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 Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7js-highlevel by itext.

the class AlternatingBackgroundTableRenderer method draw.

@Override
public void draw(DrawContext drawContext) {
    for (int i = 0; i < rows.size() && null != rows.get(i) && null != rows.get(i)[0]; i++) {
        CellRenderer[] renderers = rows.get(i);
        Rectangle leftCell = renderers[0].getOccupiedAreaBBox();
        Rectangle rightCell = renderers[renderers.length - 1].getOccupiedAreaBBox();
        Rectangle rect = new Rectangle(leftCell.getLeft(), leftCell.getBottom(), rightCell.getRight() - leftCell.getLeft(), leftCell.getHeight());
        PdfCanvas canvas = drawContext.getCanvas();
        canvas.saveState();
        if (isOdd) {
            canvas.setFillColor(ColorConstants.LIGHT_GRAY);
            isOdd = false;
        } else {
            canvas.setFillColor(ColorConstants.YELLOW);
            isOdd = true;
        }
        canvas.rectangle(rect);
        canvas.fill();
        canvas.restoreState();
    }
    super.draw(drawContext);
}
Also used : Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) CellRenderer(com.itextpdf.layout.renderer.CellRenderer)

Example 3 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7js-highlevel by itext.

the class C02E11_JekyllHydeV7 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) };
    DocumentRenderer renderer = new MyColumnRenderer(document, columns);
    document.setRenderer(renderer);
    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();
    renderer.flush();
    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) DocumentRenderer(com.itextpdf.layout.renderer.DocumentRenderer) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) PdfFont(com.itextpdf.kernel.font.PdfFont) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 4 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7js-highlevel by itext.

the class C04E10_NestedLists 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 list1 = new List(ListNumberingType.DECIMAL);
    List listEL = new List(ListNumberingType.ENGLISH_LOWER);
    listEL.add("Dr. Jekyll");
    listEL.add("Mr. Hyde");
    ListItem liEL = new ListItem();
    liEL.add(listEL);
    list1.add(liEL);
    List listEU = new List(ListNumberingType.ENGLISH_UPPER);
    listEU.add("Dr. Jekyll");
    listEU.add("Mr. Hyde");
    ListItem liEU = new ListItem();
    liEU.add(listEU);
    list1.add(liEU);
    ListItem li1 = new ListItem();
    li1.add(list1);
    list.add(li1);
    ListItem li = new ListItem();
    List listGL = new List(ListNumberingType.GREEK_LOWER);
    listGL.add("Dr. Jekyll");
    listGL.add("Mr. Hyde");
    li.add(listGL);
    List listGU = new List(ListNumberingType.GREEK_UPPER);
    listGU.add("Dr. Jekyll");
    listGU.add("Mr. Hyde");
    li.add(listGU);
    List listRL = new List(ListNumberingType.ROMAN_LOWER);
    listRL.add("Dr. Jekyll");
    listRL.add("Mr. Hyde");
    li.add(listRL);
    List listRU = new List(ListNumberingType.ROMAN_UPPER);
    listRU.add("Dr. Jekyll");
    listRU.add("Mr. Hyde");
    li.add(listRU);
    list.add(li);
    List listZ1 = new List(ListNumberingType.ZAPF_DINGBATS_1);
    listZ1.add("Dr. Jekyll");
    listZ1.add("Mr. Hyde");
    ListItem liZ1 = new ListItem();
    liZ1.add(listZ1);
    List listZ2 = new List(ListNumberingType.ZAPF_DINGBATS_2);
    listZ2.add("Dr. Jekyll");
    listZ2.add("Mr. Hyde");
    ListItem liZ2 = new ListItem();
    liZ2.add(listZ2);
    List listZ3 = new List(ListNumberingType.ZAPF_DINGBATS_3);
    listZ3.add("Dr. Jekyll");
    listZ3.add("Mr. Hyde");
    ListItem liZ3 = new ListItem();
    liZ3.add(listZ3);
    List listZ4 = new List(ListNumberingType.ZAPF_DINGBATS_4);
    listZ4.add("Dr. Jekyll");
    listZ4.add("Mr. Hyde");
    ListItem liZ4 = new ListItem();
    liZ4.add(listZ4);
    listZ3.add(liZ4);
    listZ2.add(liZ3);
    listZ1.add(liZ2);
    list.add(liZ1);
    document.add(list);
    // Close document
    document.close();
}
Also used : ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PageSize(com.itextpdf.kernel.geom.PageSize) Rectangle(com.itextpdf.kernel.geom.Rectangle) 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)

Example 5 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle 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)

Aggregations

Rectangle (com.itextpdf.kernel.geom.Rectangle)118 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)76 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)76 Test (org.junit.Test)76 PdfString (com.itextpdf.kernel.pdf.PdfString)42 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)41 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)37 ArrayList (java.util.ArrayList)29 PdfReader (com.itextpdf.kernel.pdf.PdfReader)22 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)16 Paragraph (com.itextpdf.layout.element.Paragraph)15 PdfFont (com.itextpdf.kernel.font.PdfFont)12 Document (com.itextpdf.layout.Document)12 Canvas (com.itextpdf.layout.Canvas)11 PdfPage (com.itextpdf.kernel.pdf.PdfPage)10 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)9 LogMessages (com.itextpdf.test.annotations.LogMessages)9 AreaBreak (com.itextpdf.layout.element.AreaBreak)8 PdfCleanUpLocation (com.itextpdf.pdfcleanup.PdfCleanUpLocation)8 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)7