I want to replace a page from the targetDoc
with a page from the srcDoc
, however, I cannot find a way to preserve (or recreate) the bookmark (and the bookmark's position in the document's outline). The original page was pointed to by a bookmark in the document outline and I want this bookmark to stay right at its place pointing to a page which was inserted instead of original page. For example:
PdfDocument srcDoc=new PdfDocument(new PdfReader("c:\\temp\\srcdoc.pdf"));
PdfDocument targetDoc = new PdfDocument(new PdfReader("c:\\temp\\Untitled 1.pdf"),new PdfWriter("c:\\temp\\result.pdf"));
targetDoc.removePage(1);
/*
* The bookmark to page is also removed with the removePage command.
* How to preserve/recreate it to point to the page inserted in the following step?
*/
srcDoc.initializeOutlines(); // it doesn't affect the result
srcDoc.copyPagesTo(1, 1, targetDoc,1);
targetDoc.close();
srcDoc.close();