Search in sources :

Example 21 with AreaBreak

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

the class JekyllHydeV6 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);
    // Set column parameters
    float offSet = 27;
    float gutter = 18;
    float columnWidth = (PageSize.A4.getWidth() - offSet * 2) / 3 - gutter;
    float columnHeight = PageSize.A4.getHeight() - offSet * 2;
    // Define column areas
    Rectangle[] columns = { new Rectangle(offSet + gutter * 0.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth + gutter * 1.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth * 2 + gutter * 2.5f, 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).setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    boolean chapter = false;
    Div div = new Div();
    AreaBreak areaBreak = new AreaBreak(AreaBreakType.NEXT_AREA);
    String line;
    while ((line = br.readLine()) != null) {
        div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
        div.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0));
        while ((line = br.readLine()) != null) {
            div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36));
            if (line.isEmpty()) {
                document.add(div);
                if (chapter) {
                    document.add(areaBreak);
                }
                div = new Div();
                chapter = true;
                break;
            }
        }
    }
    document.add(div);
    // 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) Div(com.itextpdf.layout.element.Div) ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfFont(com.itextpdf.kernel.font.PdfFont) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 22 with AreaBreak

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

the class 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, PageSize.A4);
    // Set column parameters
    float offSet = 27;
    float gutter = 18;
    float columnWidth = (PageSize.A4.getWidth() - offSet * 2) / 3 - gutter;
    float columnHeight = PageSize.A4.getHeight() - offSet * 2;
    // Define column areas
    Rectangle[] columns = { new Rectangle(offSet + gutter * 0.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth + gutter * 1.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth * 2 + gutter * 2.5f, 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).setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    boolean chapter = false;
    Div div = new Div();
    AreaBreak areaBreak = new AreaBreak(AreaBreakType.NEXT_PAGE);
    String line;
    while ((line = br.readLine()) != null) {
        div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
        div.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0));
        while ((line = br.readLine()) != null) {
            div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36));
            if (line.isEmpty()) {
                document.add(div);
                if (chapter) {
                    document.add(areaBreak);
                }
                div = new Div();
                chapter = true;
                break;
            }
        }
    }
    document.add(div);
    // 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) Div(com.itextpdf.layout.element.Div) ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfFont(com.itextpdf.kernel.font.PdfFont) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 23 with AreaBreak

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

the class C06E09_Annotation method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    PdfAction js = PdfAction.createJavaScript("app.alert('Boo!');");
    PdfAnnotation la1 = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).setHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT).setAction(js).setBorderStyle(PdfAnnotation.STYLE_UNDERLINE);
    Link link1 = new Link("here", (PdfLinkAnnotation) la1);
    document.add(new Paragraph().add("Click ").add(link1).add(" if you want to be scared."));
    // here we need to add a page to the document beforehand, because we'll need to get its instance for destination creation
    pdf.addNewPage();
    PdfAnnotation la2 = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).setDestination(PdfExplicitDestination.createFit(pdf.getPage(2))).setHighlightMode(PdfAnnotation.HIGHLIGHT_PUSH).setBorderStyle(PdfAnnotation.STYLE_INSET);
    Link link2 = new Link("next page", (PdfLinkAnnotation) la2);
    document.add(new Paragraph().add("Go to the ").add(link2).add(" if you're too scared."));
    document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
    document.add(new Paragraph().add("There, there, everything is OK."));
    document.close();
}
Also used : PdfAction(com.itextpdf.kernel.pdf.action.PdfAction) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfLinkAnnotation(com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation) PdfAnnotation(com.itextpdf.kernel.pdf.annot.PdfAnnotation) Rectangle(com.itextpdf.kernel.geom.Rectangle) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Link(com.itextpdf.layout.element.Link) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 24 with AreaBreak

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

the class C07E01_EventHandlers method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    pdf.getCatalog().setPageLayout(PdfName.TwoColumnLeft);
    PageRotationEventHandler eventHandler = new PageRotationEventHandler();
    pdf.addEventHandler(PdfDocumentEvent.START_PAGE, eventHandler);
    Document document = new Document(pdf, PageSize.A8);
    document.add(new Paragraph("Dr. Jekyll"));
    eventHandler.setRotation(INVERTEDPORTRAIT);
    document.add(new AreaBreak());
    document.add(new Paragraph("Mr. Hyde"));
    eventHandler.setRotation(LANDSCAPE);
    document.add(new AreaBreak());
    document.add(new Paragraph("Dr. Jekyll"));
    eventHandler.setRotation(SEASCAPE);
    document.add(new AreaBreak());
    document.add(new Paragraph("Mr. Hyde"));
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) 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)

Example 25 with AreaBreak

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

the class C06E08_ExplicitDestinations method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    // here we need to add pages to the document beforehand, because we'll need to get their instances for destination creation
    pdf.addNewPage();
    pdf.addNewPage();
    PdfDestination jekyll = PdfExplicitDestination.createFitH(pdf.getPage(1), 416);
    PdfDestination hyde = PdfExplicitDestination.createXYZ(pdf.getPage(1), 150, 516, 2);
    PdfDestination jekyll2 = PdfExplicitDestination.createFitR(pdf.getPage(2), 50, 380, 130, 440);
    document.add(new Paragraph().add(new Link("Link to Dr. Jekyll", jekyll)));
    document.add(new Paragraph().add(new Link("Link to Mr. Hyde", hyde)));
    document.add(new Paragraph().add(new Link("Link to Dr. Jekyll on page 2", jekyll2)));
    document.add(new Paragraph().setFixedPosition(50, 400, 80).add("Dr. Jekyll"));
    document.add(new Paragraph().setFixedPosition(150, 500, 80).add("Mr. Hyde"));
    document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
    document.add(new Paragraph().setFixedPosition(50, 400, 80).add("Dr. Jekyll on page 2"));
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDestination(com.itextpdf.kernel.pdf.navigation.PdfDestination) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Link(com.itextpdf.layout.element.Link) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

AreaBreak (com.itextpdf.layout.element.AreaBreak)26 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)25 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)25 Document (com.itextpdf.layout.Document)25 Paragraph (com.itextpdf.layout.element.Paragraph)20 PdfFont (com.itextpdf.kernel.font.PdfFont)17 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)17 BufferedReader (java.io.BufferedReader)13 FileReader (java.io.FileReader)13 Rectangle (com.itextpdf.kernel.geom.Rectangle)8 DottedLine (com.itextpdf.kernel.pdf.canvas.draw.DottedLine)7 Tab (com.itextpdf.layout.element.Tab)7 TabStop (com.itextpdf.layout.element.TabStop)7 ArrayList (java.util.ArrayList)7 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)6 Style (com.itextpdf.layout.Style)5 SolidBorder (com.itextpdf.layout.borders.SolidBorder)5 SimpleEntry (java.util.AbstractMap.SimpleEntry)5 Image (com.itextpdf.layout.element.Image)4 PdfPage (com.itextpdf.kernel.pdf.PdfPage)3