Corrupt result file when combining PDF files

I'm combining a couple of large PDF files (>20 MB) into one using Aspose.PDF for Java (aspose-pdf-9.5.2-jdk16.jar). The resulting PDF file content is corrupt. It can be open with Adobe PDF Reader, put parts of pages are blank.


Below is the snippet of code I'm using to combine multiple PDF files, create bookmarks and set the default page mode. If comment out all the lines of code that set the default page mode, the resulting file content looks ok. However, if I take that resulting PDF file and combine it with another PDF, I get the corrupt file content (parts of pages are blank).


System is Windows 7 with 8GB of memory. Using latest version of Java 7. Using a 30 day license for Aspose.PDF for Java.


Thanks







final PdfDocumentInfo[] documentInfos = new PdfDocumentInfo[documents.size()];

// Collect the location and page count for each source PDF file
int docIndex = 0;
for (Document document : documents) {
final String docFileLocation = document.getPath();
final String docTitle = document.getLabel();
final PdfFileInfo pdfFileInfo = new PdfFileInfo(docFileLocation, ""); //$NON-NLS-1$

documentFileLocations[docIndex] = docFileLocation;
documentInfos[docIndex] = new PdfDocumentInfo(docTitle, pdfFileInfo.getNumberOfPages());

docIndex++;
}

final java.io.File combinedDocsPdf = java.io.File.createTempFile("docs", null); //$NON-NLS-1$
final String combinedDocsPdfFileLocation = combinedDocsPdf.getAbsolutePath();

// Merge into destination PDF
final PdfFileEditor pdfFileEditor = new PdfFileEditor();
pdfFileEditor.setOwnerPassword(""); //$NON-NLS-1$
pdfFileEditor.concatenate(documentFileLocations, combinedDocsPdfFileLocation);

// Create the bookmarks in the destination PDF
int counter = 1;
int pageNumber = 1;

Bookmark topLevelBookmark = new Bookmark();
topLevelBookmark.setTitle("Document Bookmarks");
topLevelBookmark.setOpen(true);
topLevelBookmark.setPageNumber(pageNumber);

Bookmarks docBookmarks = new Bookmarks();
for (PdfDocumentInfo documentInfo : documentInfos) {
Bookmark docBookmark = new Bookmark();
docBookmark.setTitle(counter + ". " + documentInfo.title); //$NON-NLS-1$
docBookmark.setOpen(true);
docBookmark.setPageNumber(pageNumber);

docBookmarks.add(docBookmark);
pageNumber += documentInfo.pageCount;
}
topLevelBookmark.setChildItems(docBookmarks);

PdfBookmarkEditor pdfBookmarkEditor = new PdfBookmarkEditor();
pdfBookmarkEditor.bindPdf(combinedDocsPdfFileLocation);
pdfBookmarkEditor.deleteBookmarks();
pdfBookmarkEditor.createBookmarks(topLevelBookmark);
pdfBookmarkEditor.save(combinedDocsPdfFileLocation);
pdfBookmarkEditor.close();

// Open the bookmark view by default
PdfContentEditor pdfContentEditor = new PdfContentEditor();
pdfContentEditor.bindPdf(combinedDocsPdfFileLocation);
pdfContentEditor.changeViewerPreference(ViewerPreference.PAGE_MODE_USE_OUTLINES);
pdfContentEditor.save(combinedDocsPdfFileLocation);
pdfContentEditor.close();

Hi Simon,


Thanks for your inquiry. We will appreciate it if you please share your sample PDF documents, so we will test the scenario and will update you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Sorry for the delay, attached is a test file you can use (just make a copy of it, then try merging them together as per code above)

Hi Simon,


Thanks for sharing the resource file.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWJAVA-34581 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.