How to create, write and read from a pdf file in Java?
Posted by Paul on April 24th 2018 14:39 PM
PDF stands for Portable Document Format, which is used while representing the documents in a way, which is not dependent of any application software, hardware, and operating systems. In Java pdf file can be read using iText library. How to include iText in project (Eclipse) : 1. Download zip file from "https://pdfbox.apache.org/download.cgi#18x" 2. Extract .jar file from it. 3. Right click on current project in your IDE (eclipse). 4. Goto Build Path -> Configure Build Path 5. Move to Libraries tab 6. Click on Add External Jars 7. Select downloaded .jar file and click on OK Create new pdf file and write content to it :
Posted by Paul on April 24th 2018 14:42 PM
Read pdf file in Java : iText library provides certain methods using which you can get number pages from a particular pdf file, print contents of file, and also check whether the pdf file has been tampered or not. getNumberOfPages() : This method returns, number of pages a pdf file has. getTextFromPage(obj, page_number) : This method returns contents from a particular page. isTampered() : This method checks whether a particular pdf file has been tempered or not. isEncrypted() : This method checks whether a particular pdf file has been encrypted or not. Here is the code to read pdf file in Java: