Search in sources :

Example 1 with SolidBorder

use of com.itextpdf.layout.borders.SolidBorder 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 SolidBorder

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

the class C04E03_LineSeparatorExample method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    SolidLine line = new SolidLine(1f);
    line.setColor(ColorConstants.RED);
    LineSeparator ls = new LineSeparator(line);
    ls.setWidth(UnitValue.createPercentValue(50));
    ls.setMarginTop(5);
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    for (List<String> record : resultSet) {
        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 div = new Div().setKeepTogether(true).setBorderLeft(new SolidBorder(2)).setPaddingLeft(3).setMarginBottom(10).add(new Paragraph(movie.setFontSize(14f))).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);
        }
        div.add(ls);
        document.add(div);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SolidBorder(com.itextpdf.layout.borders.SolidBorder) SolidLine(com.itextpdf.kernel.pdf.canvas.draw.SolidLine) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) File(java.io.File)

Example 3 with SolidBorder

use of com.itextpdf.layout.borders.SolidBorder 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 4 with SolidBorder

use of com.itextpdf.layout.borders.SolidBorder 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 5 with SolidBorder

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

the class ImageProperties method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Image img1 = new Image(ImageDataFactory.create(TEST1));
    img1.scaleToFit(100, 100).setDestination("Top");
    document.add(img1);
    Image img2 = new Image(ImageDataFactory.create(TEST2));
    img2.setHeight(300);
    document.add(img2);
    Image img3 = new Image(ImageDataFactory.create(TEST3));
    img3.scaleToFit(100, 100);
    img3.setBackgroundColor(ColorConstants.BLUE);
    document.add(img3);
    Image img4 = new Image(ImageDataFactory.create(TEST4));
    img4.scaleToFit(100, 100);
    img4.setBackgroundColor(ColorConstants.RED);
    document.add(img4);
    Image img5 = new Image(ImageDataFactory.create(TEST5));
    img5.scaleToFit(50, 50);
    Style style = new Style();
    style.setBorderRight(new SolidBorder(2));
    img5.addStyle(style);
    document.add(img5);
    Image img6 = new Image(ImageDataFactory.create(TEST6));
    PdfAction top = PdfAction.createGoTo("Top");
    img6.scaleToFit(100, 100).setAction(top);
    document.add(img6);
    document.close();
}
Also used : PdfAction(com.itextpdf.kernel.pdf.action.PdfAction) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Style(com.itextpdf.layout.Style) 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)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)14 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)14 Document (com.itextpdf.layout.Document)14 SolidBorder (com.itextpdf.layout.borders.SolidBorder)14 Paragraph (com.itextpdf.layout.element.Paragraph)9 Style (com.itextpdf.layout.Style)7 AreaBreak (com.itextpdf.layout.element.AreaBreak)5 PdfFont (com.itextpdf.kernel.font.PdfFont)4 Image (com.itextpdf.layout.element.Image)4 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)4 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)3 Cell (com.itextpdf.layout.element.Cell)3 Link (com.itextpdf.layout.element.Link)3 Table (com.itextpdf.layout.element.Table)3 File (java.io.File)3 List (java.util.List)3 PdfAction (com.itextpdf.kernel.pdf.action.PdfAction)2 DottedBorder (com.itextpdf.layout.borders.DottedBorder)2 Div (com.itextpdf.layout.element.Div)2 Text (com.itextpdf.layout.element.Text)2