HI Disha, You can do it by two ways.
Method 1 : Using overlay
- Overlay is nothing but a Mendix document Template with the actual text formatted the way you need
- In a Microflow, you can retrieve your existing document and generate a new document from overlay
- Pass these two documents to a Java action
- Apache PDFBox the default PDF framework for Mendix has Overlay class, you can use it to merge your documents
- Refer sample programs here : https://www.programcreek.com/java-api-examples/?api=org.apache.pdfbox.multipdf.Overlay
- Use OverlayPdfDocument from community commons
Thank you @Ronald. Completely forgot about those classes
Method 2 : Directly write the Text in position within the document
- In the microflow, retrieve the document
- Pass the document to java action along with the text to be written on it
- Use PDPageContentStream to write text in the PDF
- Refer : https://www.tutorialspoint.com/pdfbox/pdfbox_adding_text.htm
I have used both method in different contexts and both works just fine.