Search in sources :

Example 11 with Canvas

use of com.itextpdf.layout.Canvas in project pdf-editor by Pdf-Creator.

the class PDFDocument method addRectangleWithImageItem.

public void addRectangleWithImageItem(ImageItem imageItem) throws MalformedURLException {
    PdfCanvas canvas = new PdfCanvas(currentPage);
    Rectangle rect = new Rectangle(imageItem.getX(), imageItem.getY(), imageItem.getW(), imageItem.getH());
    canvas.setStrokeColor(imageItem.getRectangleStrokeColor()).setFillColor(imageItem.getRectangleFillColor()).rectangle(rect).fill().stroke();
    ImageData data = ImageDataFactory.create(imageItem.getImagePath());
    Image image = new Image(data);
    image.setFixedPosition(imageItem.getX(), imageItem.getY());
    image.scaleAbsolute(imageItem.getW(), imageItem.getH());
    new Canvas(canvas, rect).add(image);
}
Also used : ImageData(com.itextpdf.io.image.ImageData) 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) BufferedImage(java.awt.image.BufferedImage) Image(com.itextpdf.layout.element.Image)

Example 12 with Canvas

use of com.itextpdf.layout.Canvas in project pdf-editor by Pdf-Creator.

the class PDFDocument method addRectangleWithTextItem.

public void addRectangleWithTextItem(TextItem textItem) {
    // creating canvas on current page
    PdfCanvas canvas = new PdfCanvas(currentPage);
    // creating rectangle on canvas
    Rectangle rect = new Rectangle(textItem.getX(), textItem.getY(), textItem.getW(), textItem.getH());
    // drawing rectangle
    canvas.setStrokeColor(textItem.getRectangleStrokeColor()).setFillColor(textItem.getRectangleFillColor()).rectangle(rect).fill().stroke();
    // adding text to rectangle;
    Paragraph paragraph = new Paragraph(textItem.getText());
    paragraph.setFontColor(textItem.getFontColor());
    new Canvas(canvas, rect).add(paragraph);
}
Also used : 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) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)12 Canvas (com.itextpdf.layout.Canvas)12 Rectangle (com.itextpdf.kernel.geom.Rectangle)11 Paragraph (com.itextpdf.layout.element.Paragraph)8 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)7 PdfPage (com.itextpdf.kernel.pdf.PdfPage)7 PdfFont (com.itextpdf.kernel.font.PdfFont)6 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)6 Text (com.itextpdf.layout.element.Text)4 ImageData (com.itextpdf.io.image.ImageData)2 Image (com.itextpdf.layout.element.Image)2 BufferedImage (java.awt.image.BufferedImage)2 GlyphLine (com.itextpdf.io.font.otf.GlyphLine)1 PdfDocumentEvent (com.itextpdf.kernel.events.PdfDocumentEvent)1 PdfException (com.itextpdf.kernel.exceptions.PdfException)1 PdfDictionary (com.itextpdf.kernel.pdf.PdfDictionary)1 PdfName (com.itextpdf.kernel.pdf.PdfName)1 PdfString (com.itextpdf.kernel.pdf.PdfString)1 CanvasArtifact (com.itextpdf.kernel.pdf.canvas.CanvasArtifact)1 Table (com.itextpdf.layout.element.Table)1