public void tearDown() throws Exception {
cleanTempFiles();
}
public void mergeAndStampPdf(boolean resetStampEachPage, File[] in, File out, File stamp) throws Exception {
Document document = new Document();
PdfCopy writer = new PdfSmartCopy(document, new FileOutputStream(out));
document.open();
int stampPageNum = 1;
PdfReader stampReader = new PdfReader(stamp.getPath());
for (int inNum = 0; inNum < in.length; inNum++){
// create a reader for the input document
PdfReader documentReader = new PdfReader(in[inNum].getPath());
for (int pageNum = 1; pageNum <= documentReader.getNumberOfPages(); pageNum++){
// import a page from the main file
PdfImportedPage mainPage = writer.getImportedPage(documentReader, pageNum);
// make a stamp from the page and get under content...
PdfCopy.PageStamp pageStamp = writer.createPageStamp(mainPage);
// import a page from a file with the stamp...
if (resetStampEachPage)
stampReader = new PdfReader(stamp.getPath());
PdfImportedPage stampPage = writer.getImportedPage(stampReader, stampPageNum++);
// add the stamp template, update stamp, and add the page
pageStamp.getOverContent().addTemplate(stampPage, 0, 0);
pageStamp.alterContents();
writer.addPage(mainPage);
if (stampPageNum > stampReader.getNumberOfPages())
stampPageNum = 1;
}
}
writer.close();
document.close();
}