@Anmol Jain has given the idea and I explored the possibilities using LibreOffice. I am adopting the solution to avoid
- Using jar files having vulnerabilities(I am not sure how critical are those)
- Retaining exact formatting of the document with all the contents like graphs, images, tables, and of course paragraphs
- Diving deep into the Apache POI and iText APIs
LibreOffice is Opensource and should work on Windows, Linux and macOS . What else is needed!!!
Please refer the following thread capturing all my findings and working script.
LibreOffice Command Line Option to convert document to PDF