Q: How can I generate a PDF document from overlaying one PDF document on another? We’re trying to overlay our company’s letterhead onto existing documents.

A: Our Java PDF library jPDFProcess can overlay one document on top of another. The function to look at is called appendPageContent and is found at the PDFPage level.

Note that the same function can be used for many purposes:

  • overlay one page on top of another
  • but also draw or impose multiple pages on a big page  (this process is also called imposition in the pre-press / print industry).

The following lines of code illustrate how to load two documents, overlay the first page from one document onto the first page of the first document, and then save the resulting document:

PDFDocument pdf1 = new PDFDocument("input1.pdf", null);
PDFDocument pdf2 = new PDFDocument("input2.pdf", null);
PDFPage page1 = pdf1.getPage(0);
PDFPage page2 = pdf2.getPage(0);
page1.appendPageContent(page2, 0, 0, 1, 1);

The arguments are the x, y positions on the target page and the x and y scales.  You can find the details in the Javadoc documentation.