Search in sources :

Example 1 with Div

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

the class C04E01_DivExample1 method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    for (List<String> record : resultSet) {
        Div div = new Div().setBorderLeft(new SolidBorder(2)).setPaddingLeft(3).setMarginBottom(10);
        String url = String.format("http://www.imdb.com/title/tt%s", record.get(0));
        Link movie = new Link(record.get(2), PdfAction.createURI(url));
        div.add(new Paragraph(movie.setFontSize(14))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
        File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
        if (file.exists()) {
            Image img = new Image(ImageDataFactory.create(file.getPath()));
            img.scaleToFit(10000, 120);
            div.add(img);
        }
        document.add(div);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SolidBorder(com.itextpdf.layout.borders.SolidBorder) Paragraph(com.itextpdf.layout.element.Paragraph) Div(com.itextpdf.layout.element.Div) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) File(java.io.File) Link(com.itextpdf.layout.element.Link)

Example 2 with Div

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

the class C04E05_ParagraphAndDiv2 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", "uk", 3, 3));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    String line;
    Div div = new Div();
    while ((line = br.readLine()) != null) {
        document.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0).setKeepWithNext(true));
        div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
        while ((line = br.readLine()) != null) {
            div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36));
            if (line.isEmpty()) {
                document.add(div);
                break;
            }
        }
    }
    document.add(div);
    // Close document
    document.close();
}
Also used : Div(com.itextpdf.layout.element.Div) 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 3 with Div

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

the class C04E02_DivExample2 method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    for (List<String> record : resultSet) {
        Div div = new Div().setKeepTogether(true).setBorderLeft(new SolidBorder(2)).setPaddingLeft(3).setMarginBottom(10);
        String url = String.format("http://www.imdb.com/title/tt%s", record.get(0));
        Link movie = new Link(record.get(2), PdfAction.createURI(url));
        div.add(new Paragraph(movie.setFontSize(14))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
        File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
        if (file.exists()) {
            Image img = new Image(ImageDataFactory.create(file.getPath()));
            img.scaleToFit(10000, 120);
            div.add(img);
        }
        document.add(div);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SolidBorder(com.itextpdf.layout.borders.SolidBorder) Paragraph(com.itextpdf.layout.element.Paragraph) Div(com.itextpdf.layout.element.Div) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) File(java.io.File) Link(com.itextpdf.layout.element.Link)

Example 4 with Div

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

the class C07E03_PageXofY method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    pdf.addEventHandler(PdfDocumentEvent.START_PAGE, new Header("The Strange Case of Dr. Jekyll and Mr. Hyde"));
    PageXofY event = new PageXofY(pdf);
    pdf.addEventHandler(PdfDocumentEvent.END_PAGE, event);
    // 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));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    String line;
    Div div = new Div();
    while ((line = br.readLine()) != null) {
        document.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0).setKeepWithNext(true));
        div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
        while ((line = br.readLine()) != null) {
            div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36).setMultipliedLeading(1.2f));
            if (line.isEmpty()) {
                document.add(div);
                break;
            }
        }
    }
    document.add(div);
    event.writeTotal(pdf);
    // Close document
    document.close();
}
Also used : Div(com.itextpdf.layout.element.Div) 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 5 with Div

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

the class C07E02_TextWatermark method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    pdf.addEventHandler(PdfDocumentEvent.END_PAGE, new TextWatermark());
    // 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));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    String line;
    Div div = new Div();
    while ((line = br.readLine()) != null) {
        document.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0).setKeepWithNext(true));
        div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
        while ((line = br.readLine()) != null) {
            div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36).setMultipliedLeading(1.2f));
            if (line.isEmpty()) {
                document.add(div);
                break;
            }
        }
    }
    document.add(div);
    // Close document
    document.close();
}
Also used : Div(com.itextpdf.layout.element.Div) 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)

Aggregations

Div (com.itextpdf.layout.element.Div)11 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)10 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)10 Document (com.itextpdf.layout.Document)10 Paragraph (com.itextpdf.layout.element.Paragraph)10 PdfFont (com.itextpdf.kernel.font.PdfFont)8 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)8 BufferedReader (java.io.BufferedReader)8 FileReader (java.io.FileReader)8 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)2 Rectangle (com.itextpdf.kernel.geom.Rectangle)2 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)2 SolidBorder (com.itextpdf.layout.borders.SolidBorder)2 AreaBreak (com.itextpdf.layout.element.AreaBreak)2 Image (com.itextpdf.layout.element.Image)2 Link (com.itextpdf.layout.element.Link)2 File (java.io.File)2 List (java.util.List)2 DottedLine (com.itextpdf.kernel.pdf.canvas.draw.DottedLine)1 LineSeparator (com.itextpdf.layout.element.LineSeparator)1