Hi,
We are trying to replace a different product jar file with aspose and we are left with just one item that is bookmarks - creating and preserving them but when I am using the following code to add bookmarks to an existing pdf file. The issue is it creates a parent bookmark as bookmark 0 but only creates 2 child as child bookmark 2 and 3. Below is the image how it is creating.
![]()
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C:\\documents\\testdata\\GI_3a8b4e21-2063-40ec-8b6c-7daa2bfc2fac.pdf");
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
bookmarkEditor.bindPdf(pdfDocument);
com.aspose.pdf.OutlineItemCollection parentOutline = new com.aspose.pdf.OutlineItemCollection(pdfDocument.getOutlines());
// Extract bookmarks
Bookmarks bookmarks = bookmarkEditor.extractBookmarks();
com.aspose.pdf.facades.Bookmarks childList = new com.aspose.pdf.facades.Bookmarks();
for(int i = 0; i < 3; i++)
{
Bookmark bookMark = new Bookmark();
bookMark.setPageNumber(i);
bookMark.setTitle("Parent Bookmark " + i);
bookMark.setLevel(1);
for (int j = 0; j < 4; j++)
{
com.aspose.pdf.facades.Bookmark bookmark2 = new com.aspose.pdf.facades.Bookmark();
bookmark2.setPageNumber(1);
bookmark2.setTitle("child bookmark " + j);
bookmark2.setLevel(2);
childList.add(bookmark2);
}
bookMark.setChildItem(childList);
bookmarkEditor.createBookmarks(bookMark);
}
bookmarkEditor.save("C:\\users\\mathurrk\\bookEdit.pdf");
Thanks in advance.
We are trying to replace a different product jar file with aspose and we are left with just one item that is bookmarks - creating and preserving them but when I am using the following code to add bookmarks to an existing pdf file. The issue is it creates a parent bookmark as bookmark 0 but only creates 2 child as child bookmark 2 and 3. Below is the image how it is creating.
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C:\\documents\\testdata\\GI_3a8b4e21-2063-40ec-8b6c-7daa2bfc2fac.pdf");
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
bookmarkEditor.bindPdf(pdfDocument);
com.aspose.pdf.OutlineItemCollection parentOutline = new com.aspose.pdf.OutlineItemCollection(pdfDocument.getOutlines());
// Extract bookmarks
Bookmarks bookmarks = bookmarkEditor.extractBookmarks();
com.aspose.pdf.facades.Bookmarks childList = new com.aspose.pdf.facades.Bookmarks();
for(int i = 0; i < 3; i++)
{
Bookmark bookMark = new Bookmark();
bookMark.setPageNumber(i);
bookMark.setTitle("Parent Bookmark " + i);
bookMark.setLevel(1);
for (int j = 0; j < 4; j++)
{
com.aspose.pdf.facades.Bookmark bookmark2 = new com.aspose.pdf.facades.Bookmark();
bookmark2.setPageNumber(1);
bookmark2.setTitle("child bookmark " + j);
bookmark2.setLevel(2);
childList.add(bookmark2);
}
bookMark.setChildItem(childList);
bookmarkEditor.createBookmarks(bookMark);
}
bookmarkEditor.save("C:\\users\\mathurrk\\bookEdit.pdf");
Thanks in advance.