Java

Convert DOC to PDF using Home Made in Java

We need portability to work with our documents anywhere portability needs have increased from day to day. PDF (Portable Document Format ) can be accessed on any budget android smartphone without breaking sweat.We have written java code.

There are many programs that can convert data but not like home made code if you documents are confidential then it is better to use this home made to code to convert the files into the PDF format.




This program allows you to convert one or many microsoft word (2007+) files to PDF files. The program extracts text, images and information about font colors, sizes and styles used in the word files. Then these things are placed in PDF files when they are generated.

The main APIs used in this program are Apache POI and iText. Apache API is used to extract information from a microsoft word file while iText is used to create a PDF file.

In the code above, the XWPFDocument (in POI library) is used to construct a Microsoft Word file. The object of this class accept the FileInputStream as its argument. The FileInputStream class is used to read the Microsoft Word file. When you have document that contains all data of the original Microsoft Word file, you can get the paragraphobjects inside the document by using the getParagraphs() method. This method returns all paragraphs found in the original Microsoft Word file. In each paragraph object, there are many smaller items called run objects. From each run object you can extract text, image, and formatting styles that are applied to the text when the Microsoft Word file is written.
Once you have the text, images, and formatting styles data, you can write them to the destination pdf file by using classes and methods from the iText library.

Take your time to comment on our articles and code it will really help us improve a lot.

Leave a Comment