String filePath = "D:/test.pdf"
int pageOffset = 0;
ArrayList master = new ArrayList();
Document document = null;
PdfCopy writer = null;
File file = new File(filePath);
FileOutputStream out = new FileOutputStream(file);
for (int i = 0; i < receivingNo.size(); i++) {
InventoryOrderListReport report = new InventoryOrderListReport();
//start set report title values
List<String> titleValue=new ArrayList<String>();
if(searchBean.getTermianId()!=null&&!searchBean.getTermianId().trim().equals("")){
SecuOptUnitBean optUnitBean=systemLocalService.getSecuOptUnitBean(searchBean.getTermianId());
titleValue.add(optUnitBean==null?termialBlank:optUnitBean.getOptUnitName());
titleValue.add(searchBean.getTermianId());
}else{
titleValue.add("ALL");
titleValue.add("ALL");
}
if(searchBean.getClientCode().split(",").length>1){
titleValue.add("ALL");
}else{
String clientName=systemLocalService.getClientCompanyName(
searchBean.getTermianId(), searchBean.getClientCode());
titleValue.add(clientName);
}
titleValue.add(receivingNo.get(i));
report.setTitleValue(titleValue);
report.setTableValue(result);
// we create a reader for a certain document
byte[] resultPdf = report.runReport();
PdfReader reader = new PdfReader(resultPdf);
reader.consolidateNamedDestinations();
// we retrieve the total number of pages
int numberOfPages = reader.getNumberOfPages();
List bookmarks = SimpleBookmark.getBookmark(reader);
if (bookmarks != null) {
if (pageOffset != 0) {
SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
}
master.addAll(bookmarks);
}
pageOffset += numberOfPages;
if (i == 0) {
// step 1: creation of a document-object
document = new Document(reader.getPageSizeWithRotation(1));
// step 2: we create a writer that listens to the document
writer = new PdfCopy(document, out);
// step 3: we open the document
document.open();
}
// step 4: we add content
PdfImportedPage page;
for (int index = 1; index <= numberOfPages; index++) {
page = writer.getImportedPage(reader, index);
writer.addPage(page);
}
writer.freeReader(reader);
}
if (master.size() > 0) {
writer.setOutlines(master);
}
// step 5: we close the document
document.close();