Formatting the Content of a Cell in a Table of PDF using Java
iText is a Java library developed, to access and manipulate PDF files, that is to extract and modify the PDF content. iText is a Java library originally created by Bruno Lowagie which allows creating, reading, and manipulating PDF files. Java allows incorporating various fully developed packages and modules in order to work with PDF files.iText library enables the creation of a PDF document in the local directory and adding contents to the PDF file created using the java program. Here, formatting the contents of a table cell in a PDF using java can be achieved below mentioned in the article.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
- slf4j (Logging Library)
- Download the iText jar files.
- Download the slf4j jar file.
- To use the libraries add the above-downloaded jar files to the classpath of the system.
- 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 PDF Document object.
- Create a Table using a Table object and set Table Dimensions.
- Create Cells and add attributes to cell-like Text Alignment, Font Color, Background Color & Cell Content.
- Add the Cells to the Table.
Sample Input Image: This PDF file input image is used the below program to format the content of the cell.
Implementation: First cells are created in the above input PDF file and then the content of the cell is formatted
Output: In console window message is printed “Table successfully created” to show proper execution of program and changes made during execution in input file during execution is as shown.