Search in sources :

Example 81 with Document

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

the class C03E20_XObjectTypes method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    PdfFormXObject xObject1 = new PdfFormXObject(new WmfImageData(WMF), pdf);
    Image img1 = new Image(xObject1);
    document.add(img1);
    PdfReader reader = new PdfReader(SRC);
    PdfDocument existing = new PdfDocument(reader);
    PdfPage page = existing.getPage(1);
    PdfFormXObject xObject2 = page.copyAsFormXObject(pdf);
    Image img2 = new Image(xObject2);
    img2.scaleToFit(400, 400);
    document.add(img2);
    document.close();
}
Also used : WmfImageData(com.itextpdf.kernel.pdf.canvas.wmf.WmfImageData) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFormXObject(com.itextpdf.kernel.pdf.xobject.PdfFormXObject) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfPage(com.itextpdf.kernel.pdf.PdfPage) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 82 with Document

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

the class C04E04_ParagraphAndDiv1 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) {
        Paragraph title = new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0);
        div = new Div().add(title).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 83 with Document

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

the class C04E05_ParagraphAndDiv3 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).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)

Example 84 with Document

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

the class C04E07_ListTypes 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.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.DECIMAL);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ENGLISH_LOWER);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ENGLISH_UPPER);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.GREEK_LOWER);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.GREEK_UPPER);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ROMAN_LOWER);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ROMAN_UPPER);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ZAPF_DINGBATS_1);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ZAPF_DINGBATS_2);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ZAPF_DINGBATS_3);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    document.add(list);
    list = new List(ListNumberingType.ZAPF_DINGBATS_4);
    list.add("Dr. Jekyll");
    list.add("Mr. Hyde");
    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) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 85 with Document

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

the class C01E02_Text_Paragraph_Cardo2 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);
    // Add content
    Text title = new Text("The Strange Case of Dr. Jekyll and Mr. Hyde").setFont(bold);
    Text author = new Text("Robert Louis Stevenson").setFont(font);
    Paragraph p = new Paragraph().setFont(italic).add(title).add(" by ").add(author);
    document.add(p);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Text(com.itextpdf.layout.element.Text) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)132 Document (com.itextpdf.layout.Document)132 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)130 Paragraph (com.itextpdf.layout.element.Paragraph)104 PdfFont (com.itextpdf.kernel.font.PdfFont)39 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)31 BufferedReader (java.io.BufferedReader)26 FileReader (java.io.FileReader)26 AreaBreak (com.itextpdf.layout.element.AreaBreak)25 Image (com.itextpdf.layout.element.Image)25 Table (com.itextpdf.layout.element.Table)25 Cell (com.itextpdf.layout.element.Cell)21 List (java.util.List)20 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)19 File (java.io.File)16 SolidBorder (com.itextpdf.layout.borders.SolidBorder)14 ArrayList (java.util.ArrayList)14 Tab (com.itextpdf.layout.element.Tab)13 Text (com.itextpdf.layout.element.Text)13 Rectangle (com.itextpdf.kernel.geom.Rectangle)12