Drawing an Object in a PDF with Canvas using Java
To create an object in a PDF with Canvas using Java can be done by using a library called iText. iText is a Java library originally created by Bruno Lowagie which allows creating PDF, read PDF, and manipulate them.
Libraries required :
iText slf4j (Logging Library)
Example : Drawing a circle in a PDF
- Get the current working directory of the running java program to create the PDF file in the same location
- Create a PdfWriter object (from itextpdf library) which writes the PDF file to the given path
- Create an empty PdfDocument object and add a page to it using PdfPage object
- Create the canvas using the PdfCanvas object in the Pdf Page
- Create the object on the Canvas and fill the object with color
Below is the implementation of the above approach:
The PDF file is created in the specified path.
My Personal Notes arrow_drop_up
Please Login to comment...