Java Program to Tile a Page Content in a PDF
In order to tile the pages, we are going to use the iText open-source library here because iText is a world-leading F/OSS PDF library. For Tiling a page content in a PDF, we need some classes iText library. The following are the components used in creating Tiling page content.
- PdfReader class which belongs to the package com.itextpdf.text.pdf and is used to read the existing PDF Document.
- PdfWriter class belongs to the package com.itextpdf.text.pdf and is used to write content to the document.
- PdfDocument class which belongs to the package com.itextpdf.kernel.pdf. By creating this class you have to pass either a writer argument or reader argument.
- Document class belongs to the package com.itextpdf.layout. It is one of the core classes in IText. com.itextpdf.text.Document class is used to create the instance.
- Rectangle class which belongs to the package com.itextpdf.text. This class is used for setting up border color, filing a particular color, adjusting text to fit inside the rectangle.
- pdfCanvas class which belongs to the package com.itextpdf.kernel.pdf.canvas.PdfCanvas. pdfCanvas is used for writing data into page content. call pdfCanvas.release() method after you finished your use. It will save some memory.
- Close the document using the close() method as it will save some memory.
- Download iText library in the workspace.
- Create Java project
- Go to configurations and convert this project into a maven project
- Add the dependencies to the pom.xml file.
- After that create a Java class and build this code by giving a specific path of your PDF files.
PDF before tiling the page content is as follows:
Message on the output console.
PDF document is created successfully.
Also, after opening the saved PDF at the specified location you will see tiling the page content in that PDF, the new generated PDF is as follows:
My Personal Notes arrow_drop_up
Please Login to comment...