Search in sources :

Example 26 with Document

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

the class C05E05_CellPadding 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(new float[] { 2, 1, 1 }));
    table.setBackgroundColor(ColorConstants.ORANGE);
    table.setWidth(UnitValue.createPercentValue(80));
    table.setHorizontalAlignment(HorizontalAlignment.CENTER);
    table.addCell(new Cell(1, 3).add(new Paragraph("Cell with colspan 3")).setPadding(10).setBackgroundColor(ColorConstants.GREEN));
    table.addCell(new Cell(2, 1).add(new Paragraph("Cell with rowspan 2")).setPaddingLeft(30).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.BLUE));
    table.addCell(new Cell().add(new Paragraph("row 1; cell 1")).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.RED));
    table.addCell(new Cell().add(new Paragraph("row 1; cell 2")));
    table.addCell(new Cell().add(new Paragraph("row 2; cell 1")).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.RED));
    table.addCell(new Cell().add(new Paragraph("row 2; cell 2")).setPadding(10).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.RED));
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 27 with Document

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

the class C05E06_CellBorders1 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(new float[] { 2, 1, 1 }));
    table.setWidth(UnitValue.createPercentValue(80)).setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER);
    table.addCell(new Cell(1, 3).add(new Paragraph("Cell with colspan 3")).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(new DashedBorder(0.5f)));
    table.addCell(new Cell(2, 1).add(new Paragraph("Cell with rowspan 2")).setVerticalAlignment(VerticalAlignment.MIDDLE).setBorderBottom(new DottedBorder(0.5f)).setBorderLeft(new DottedBorder(0.5f)));
    table.addCell(new Cell().add(new Paragraph("row 1; cell 1")).setBorder(new DottedBorder(ColorConstants.ORANGE, 0.5f)));
    table.addCell(new Cell().add(new Paragraph("row 1; cell 2")));
    table.addCell(new Cell().add(new Paragraph("row 2; cell 1")).setBorderBottom(new SolidBorder(2)));
    table.addCell(new Cell().add(new Paragraph("row 2; cell 2")).setBorderBottom(new SolidBorder(2)));
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) DashedBorder(com.itextpdf.layout.borders.DashedBorder) 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 28 with Document

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

the class C05E06_CellBorders3 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(new float[] { 2, 1, 1 }));
    table.setWidth(UnitValue.createPercentValue(80)).setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER);
    Cell cell = new RoundedCornersCell(1, 3).add(new Paragraph("Cell with colspan 3"));
    table.addCell(cell);
    cell = new RoundedCornersCell(2, 1).add(new Paragraph("Cell with rowspan 2"));
    table.addCell(cell);
    cell = new RoundedCornersCell().add(new Paragraph("row 1; cell 1"));
    table.addCell(cell);
    cell = new RoundedCornersCell().add(new Paragraph("row 1; cell 2"));
    table.addCell(cell);
    cell = new RoundedCornersCell().add(new Paragraph("row 2; cell 1"));
    table.addCell(cell);
    cell = new RoundedCornersCell().add(new Paragraph("row 2; cell 2"));
    table.addCell(cell);
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 29 with Document

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

the class C05E07_NestedTable 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(new float[] { 1, 1 }).setWidth(UnitValue.createPercentValue(80)).setHorizontalAlignment(HorizontalAlignment.CENTER);
    table.addCell(new Cell(1, 2).add(new Paragraph("Cell with colspan 2")));
    table.addCell(new Cell().add(new Paragraph("Cell with rowspan 1")));
    Table inner = new Table(new float[] { 1, 1 });
    inner.addCell("row 1; cell 1");
    inner.addCell("row 1; cell 2");
    inner.addCell("row 2; cell 1");
    inner.addCell("row 2; cell 2");
    table.addCell(inner);
    document.add(table);
    table = new Table(new float[] { 1, 1 }).setMarginTop(10).setWidth(UnitValue.createPercentValue(80)).setHorizontalAlignment(HorizontalAlignment.CENTER);
    table.addCell(new Cell(1, 2).add(new Paragraph("Cell with colspan 2")));
    table.addCell(new Cell().add(new Paragraph("Cell with rowspan 1")));
    inner = new Table(new float[] { 1, 1 });
    inner.addCell("row 1; cell 1");
    inner.addCell("row 1; cell 2");
    inner.addCell("row 2; cell 1");
    inner.addCell("row 2; cell 2");
    table.addCell(new Cell().add(inner).setPadding(0));
    document.add(table);
    table = new Table(new float[] { 1, 1 }).setMarginTop(10).setWidth(UnitValue.createPercentValue(80)).setHorizontalAlignment(HorizontalAlignment.CENTER);
    table.addCell(new Cell(1, 2).add(new Paragraph("Cell with colspan 2")));
    table.addCell(new Cell().add(new Paragraph("Cell with rowspan 1")));
    inner = new Table(new float[] { 1, 1 }).setWidth(UnitValue.createPercentValue(100));
    inner.addCell("row 1; cell 1");
    inner.addCell("row 1; cell 2");
    inner.addCell("row 2; cell 1");
    inner.addCell("row 2; cell 2");
    table.addCell(new Cell().add(inner).setPadding(0));
    document.add(table);
    document.close();
}
Also used : Table(com.itextpdf.layout.element.Table) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Cell(com.itextpdf.layout.element.Cell) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 30 with Document

use of com.itextpdf.layout.Document 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)

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