How to Convert a Document to PDF in Java?

In software projects, there is quite often a requirement for conversion of a given file (HTML/TXT/etc.,) to a PDF file and similarly, any PDF file needs to get converted to HTML/TXT/etc., files. Even PDFs need to be stored as images of type PNG or GIF etc., Via a sample maven project, let us see the same. As it is the maven project, necessary dependencies need to be added in pom.xml

Essential Library is PDF2Dom:

  org.apache.pdfbox pdfbox-tools 2.0.25    net.sf.cssbox pdf2dom 2.0.1 

A few more dependencies are also needed. iText is needed to extract the text from a given PDF file. POI is needed to create the .docx document.

 com.itextpdf itextpdf 5.5.10  com.itextpdf.tool xmlworker 5.5.10  org.apache.poi poi-ooxml 3.15  org.apache.poi poi-scratchpad 3.15 

Example Maven Project

Let us start with the project structure and pom.xml and then will look for the required source code to convert from PDF to other formats as well as from other formats to HTML

pom.xml