// collect together
ByteArrayOutputStream baos = new ByteArrayOutputStream();
com.lowagie.text.Document document =
new com.lowagie.text.Document(pdfReaders[0].getPageSizeWithRotation(1));
PdfCopy copy = new PdfCopy(document,baos);
document.open();
String name;
ArrayList bookmarks=doBookmarks?new ArrayList():null;
try {
int size,totalPage=0;
Map parent;
for(int doc=0;doc<pdfReaders.length;doc++) {
size=pdfReaders[doc].getNumberOfPages();
PdfImportedPage ip;
// bookmarks
if(doBookmarks) {
name=pdfDocs[doc].getName();
if(!StringUtil.isEmpty(name)) {
bookmarks.add(parent=PDFUtil.generateGoToBookMark(name, totalPage+1));
}
else parent=null;
if(doHtmlBookmarks) {
java.util.List pageBM = SimpleBookmark.getBookmark(pdfReaders[doc]);
if(pageBM!=null) {
if(totalPage>0)SimpleBookmark.shiftPageNumbers(pageBM, totalPage, null);
if(parent!=null)PDFUtil.setChildBookmarks(parent,pageBM);
else bookmarks.addAll(pageBM);
}
}
}
totalPage++;
for(int page=1;page<=size;page++) {
if(page>1)totalPage++;
ip = copy.getImportedPage(pdfReaders[doc], page);
//ip.getPdfDocument().setHeader(arg0);
//ip.getPdfDocument().setFooter(arg0);
copy.addPage(ip);
}
}
if (doBookmarks && !bookmarks.isEmpty())copy.setOutlines(bookmarks);
}
finally {
document.close();
}
pdf=baos.toByteArray();
}
else if(documents.size()==1){
pdf=(documents.get(0)).render(getDimension(),unitFactor,pageContext,doHtmlBookmarks);
}
else {
pdf=getDocument().render(getDimension(),unitFactor,pageContext,doHtmlBookmarks);
}
// permission/encryption
if(PDFDocument.ENC_NONE!=encryption) {
PdfReader reader = new PdfReader(pdf);
com.lowagie.text.Document document = new com.lowagie.text.Document(reader.getPageSize(1));
document.addCreator("Railo "+Info.getVersionAsString()+" "+Info.getStateAsString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfCopy copy = new PdfCopy(document,baos);
//PdfWriter writer = PdfWriter.getInstance(document, pdfOut);
copy.setEncryption(PDFDocument.ENC_128BIT==encryption , userpassword , ownerpassword , permissions);
document.open();
int size=reader.getNumberOfPages();
for(int page=1;page<=size;page++) {
copy.addPage(copy.getImportedPage(reader, page));
}
document.close();
pdf=baos.toByteArray();
}