Here is a sample java program that uses Qoppa’s PDF library jPDFProcess to open two PDF files, flatten annotations and fields in each PDF document, then merge the two documents into one, and finally save the resulting merged document.

// Load document 1 
PDFDocument pdfDoc1 = new PDFDocument ("C:\\temp\\input1.pdf", null);
// flatten annotations in document 1 
// do not paint non printable annotations
pdfDoc1.flattenAnnotations(false);
// flatten fields
// do not paint buttons, do not paint non printable fields
pdfDoc1.flattenFields(false, false);
 
// Load document 2 
PDFDocument pdfDoc2 = new PDFDocument ("C:\\temp\\input2.pdf", null);
// flatten annotations in document 2
// do not paint non printable annotations
pdfDoc2.flattenAnnotations(false);
// flatten fields
// do not paint buttons, do not paint non printable fields
pdfDoc2.flattenFields(false, false);
 
 
// Append document 2 to document 1
pdfDoc1.appendDocument(pdfDoc2);
 
// Save the merged document
pdfDoc1.saveDocument ("C:\\temp\\output.pdf");