PDF Document Merger
Sometimes, you have to merge PDF documents. The PDF Document Merger combines PDF documents and optionally adds page numbering to the merged document. In this section we'll merge catalog.pdf
and catalog2.pdf
, which we generated in the previous sections.
1. First, create an
InputStream
array from thecatalog.pdf
andcatalog2.pdf
reports.FileInputStream[] inputStreams = new FileInputStream[2]; inputStreams[0] = new FileInputStream("catalog.pdf"); inputStreams[1] = new FileInputStream("catalog2.pdf");
2. Create a
FileOutputStream
object for the merged PDF document.FileOutputStream outputStream = new FileOutputStream( "catalog3.pdf");
3. Merge the PDF documents with the
PDFDocMerger
class.PDFDocMerger pdfMerger = new PDFDocMerger(inputStreams, outputStream);
4. To add page numbering, specify the page numbering coordinates using the
setPageNumberCoordinates
method, and set the page numbering font using thesetPagNumberFontInfo
method.pdfMerger.setPageNumberCoordinates(300,...