Take a look at Document Generation for Mendix module in Marketplace
use the below java code
Hope it helps!!!
Is the document generated in your Mendix application through a Generate Document microflow action or are you uploading it from somewhere?
If you are using the Generate Document microflow action, you can just change the “Document Type” from “Word 2007” or “Word 2003” to “PDF”.
If you are uploading it and hoping to convert it, there are a few Java libraries you can look at. One that springs to mind is docx4j or Apache POI. A quick search on StackOverflow should give you a few options.
This question has been asked on the forum a few times before, so a quick search may provide you with a suitable answer.