Search in sources :

Example 1 with PdfCanvas

use of com.itextpdf.kernel.pdf.canvas.PdfCanvas in project i7js-highlevel by itext.

the class AlternatingBackgroundTableRenderer method draw.

@Override
public void draw(DrawContext drawContext) {
    for (int i = 0; i < rows.size() && null != rows.get(i) && null != rows.get(i)[0]; i++) {
        CellRenderer[] renderers = rows.get(i);
        Rectangle leftCell = renderers[0].getOccupiedAreaBBox();
        Rectangle rightCell = renderers[renderers.length - 1].getOccupiedAreaBBox();
        Rectangle rect = new Rectangle(leftCell.getLeft(), leftCell.getBottom(), rightCell.getRight() - leftCell.getLeft(), leftCell.getHeight());
        PdfCanvas canvas = drawContext.getCanvas();
        canvas.saveState();
        if (isOdd) {
            canvas.setFillColor(ColorConstants.LIGHT_GRAY);
            isOdd = false;
        } else {
            canvas.setFillColor(ColorConstants.YELLOW);
            isOdd = true;
        }
        canvas.rectangle(rect);
        canvas.fill();
        canvas.restoreState();
    }
    super.draw(drawContext);
}
Also used : Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) CellRenderer(com.itextpdf.layout.renderer.CellRenderer)

Example 2 with PdfCanvas

use of com.itextpdf.kernel.pdf.canvas.PdfCanvas in project i7js-highlevel by itext.

the class C03E04_JekyllHydeTabsV4 method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf, PageSize.A4.rotate());
    float[] stops = new float[] { 80, 120, 580, 590, 720 };
    List<TabStop> tabstops = new ArrayList();
    tabstops.add(new TabStop(stops[0], TabAlignment.CENTER, new DottedLine()));
    tabstops.add(new TabStop(stops[1], TabAlignment.LEFT));
    tabstops.add(new TabStop(stops[2], TabAlignment.RIGHT, new SolidLine(0.5f)));
    tabstops.add(new TabStop(stops[3], TabAlignment.LEFT));
    TabStop anchor = new TabStop(stops[4], TabAlignment.ANCHOR, new DashedLine());
    anchor.setTabAnchor(' ');
    tabstops.add(anchor);
    PdfCanvas pdfCanvas = new PdfCanvas(pdf.addNewPage());
    for (int i = 0; i < stops.length; i++) {
        pdfCanvas.moveTo(document.getLeftMargin() + stops[i], 0);
        pdfCanvas.lineTo(document.getLeftMargin() + stops[i], 595);
    }
    pdfCanvas.stroke();
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    for (List<String> record : resultSet) {
        Paragraph p = new Paragraph();
        p.addTabStops(tabstops);
        p.add(record.get(0).trim()).add(new Tab()).add(record.get(1).trim()).add(new Tab()).add(record.get(2).trim()).add(new Tab()).add(record.get(3).trim()).add(new Tab()).add(record.get(4).trim()).add(new Tab()).add(record.get(5).trim() + " \'");
        document.add(p);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ArrayList(java.util.ArrayList) TabStop(com.itextpdf.layout.element.TabStop) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) Tab(com.itextpdf.layout.element.Tab) DottedLine(com.itextpdf.kernel.pdf.canvas.draw.DottedLine) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) SolidLine(com.itextpdf.kernel.pdf.canvas.draw.SolidLine) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) ArrayList(java.util.ArrayList) List(java.util.List) DashedLine(com.itextpdf.kernel.pdf.canvas.draw.DashedLine)

Example 3 with PdfCanvas

use of com.itextpdf.kernel.pdf.canvas.PdfCanvas in project i7js-highlevel by itext.

the class C03E03_JekyllHydeTabsV3 method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf, PageSize.A4.rotate());
    float[] stops = new float[] { 80, 120, 580, 590, 720 };
    List<TabStop> tabstops = new ArrayList();
    tabstops.add(new TabStop(stops[0], TabAlignment.CENTER));
    tabstops.add(new TabStop(stops[1], TabAlignment.LEFT));
    tabstops.add(new TabStop(stops[2], TabAlignment.RIGHT));
    tabstops.add(new TabStop(stops[3], TabAlignment.LEFT));
    TabStop anchor = new TabStop(stops[4], TabAlignment.ANCHOR);
    anchor.setTabAnchor(' ');
    tabstops.add(anchor);
    PdfCanvas pdfCanvas = new PdfCanvas(pdf.addNewPage());
    for (int i = 0; i < stops.length; i++) {
        pdfCanvas.moveTo(document.getLeftMargin() + stops[i], 0);
        pdfCanvas.lineTo(document.getLeftMargin() + stops[i], 595);
    }
    pdfCanvas.stroke();
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    for (List<String> record : resultSet) {
        Paragraph p = new Paragraph();
        p.addTabStops(tabstops);
        p.add(record.get(0).trim()).add(new Tab()).add(record.get(1).trim()).add(new Tab()).add(record.get(2).trim()).add(new Tab()).add(record.get(3).trim()).add(new Tab()).add(record.get(4).trim()).add(new Tab()).add(record.get(5).trim() + " \'");
        document.add(p);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ArrayList(java.util.ArrayList) TabStop(com.itextpdf.layout.element.TabStop) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) Tab(com.itextpdf.layout.element.Tab) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with PdfCanvas

use of com.itextpdf.kernel.pdf.canvas.PdfCanvas in project i7js-highlevel by itext.

the class CanvasFontMethods method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    PdfPage page = pdf.addNewPage();
    PdfCanvas pdfCanvas = new PdfCanvas(page);
    Rectangle rectangle = new Rectangle(36, 36, 523, 770);
    Canvas canvas = new Canvas(pdfCanvas, rectangle);
    Paragraph p;
    p = new Paragraph("Testing font methods");
    canvas.add(p);
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    canvas.setFont(font);
    p = new Paragraph("Testing font methods: changed font");
    canvas.add(p);
    canvas.setFontSize(18);
    p = new Paragraph("Testing font methods: changed font size");
    canvas.add(p);
    canvas.setFontColor(ColorConstants.BLUE);
    p = new Paragraph("Testing font methods: changed color");
    canvas.add(p);
    canvas.setBold();
    p = new Paragraph("Testing font methods: to bold");
    canvas.add(p);
    canvas.setItalic();
    p = new Paragraph("Testing font methods: to italic");
    canvas.add(p);
    canvas.setProperty(Property.BOLD_SIMULATION, false);
    canvas.setProperty(Property.ITALIC_SIMULATION, false);
    canvas.setProperty(Property.FONT_COLOR, null);
    p = new Paragraph("Testing font methods: resetting style and color");
    canvas.add(p);
    canvas.setLineThrough();
    p = new Paragraph("Testing font methods: line through (default)");
    canvas.add(p);
    canvas.setProperty(Property.UNDERLINE, null);
    canvas.setUnderline();
    p = new Paragraph("Testing font methods: underline (default)");
    canvas.add(p);
    canvas.setProperty(Property.UNDERLINE, null);
    canvas.setUnderline(2, 4);
    canvas.setUnderline(ColorConstants.BLUE, 5, 0.1f, 2, -0.5f, PdfCanvasConstants.LineCapStyle.ROUND);
    p = new Paragraph("Testing font methods: underline (custom)");
    canvas.add(p);
    canvas.setProperty(Property.UNDERLINE, null);
    canvas.setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
    p = new Paragraph("Testing font methods: change text rendering mode");
    canvas.add(p);
    canvas.setStrokeWidth(0.1f);
    canvas.setStrokeColor(ColorConstants.BLUE);
    p = new Paragraph("Testing font methods: change stroke width and color");
    canvas.add(p);
    // Close document
    pdf.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Canvas(com.itextpdf.layout.Canvas) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfFont(com.itextpdf.kernel.font.PdfFont) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfPage(com.itextpdf.kernel.pdf.PdfPage) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 5 with PdfCanvas

use of com.itextpdf.kernel.pdf.canvas.PdfCanvas in project pdf-editor by Pdf-Creator.

the class PDFDocument method addRectangleWithTableItem.

public void addRectangleWithTableItem(TableItem tableItem) {
    PdfCanvas canvas = new PdfCanvas(currentPage);
    Rectangle rect = new Rectangle(tableItem.getX(), tableItem.getY(), tableItem.getW(), tableItem.getH());
    canvas.setStrokeColor(tableItem.getRectangleStrokeColor()).setFillColor(tableItem.getRectangleFillColor()).rectangle(rect).fill().stroke();
    Table table = new Table(tableItem.getCols());
    table.setFontColor(tableItem.getFontColor());
    for (String cellContent : tableItem.getCellContents()) {
        table.addCell(cellContent);
    }
    new Canvas(canvas, rect).add(table);
}
Also used : Table(com.itextpdf.layout.element.Table) Canvas(com.itextpdf.layout.Canvas) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas)

Aggregations

PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)34 Rectangle (com.itextpdf.kernel.geom.Rectangle)16 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)16 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)15 Paragraph (com.itextpdf.layout.element.Paragraph)14 Canvas (com.itextpdf.layout.Canvas)12 PdfPage (com.itextpdf.kernel.pdf.PdfPage)11 PdfFont (com.itextpdf.kernel.font.PdfFont)7 Document (com.itextpdf.layout.Document)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)6 Tab (com.itextpdf.layout.element.Tab)6 TabStop (com.itextpdf.layout.element.TabStop)5 PdfStream (com.itextpdf.kernel.pdf.PdfStream)4 Text (com.itextpdf.layout.element.Text)4 ImageData (com.itextpdf.io.image.ImageData)2 PdfArray (com.itextpdf.kernel.pdf.PdfArray)2 PdfName (com.itextpdf.kernel.pdf.PdfName)2 PdfReader (com.itextpdf.kernel.pdf.PdfReader)2