Import Bookmarks from XML to an Existing PDF File (facades)
The importBookmarksWithXml method allows you to import bookmarks into a PDF file from an XML file.
To import bookmarks:
- Create a PdfBookmarkEditor object and bind the PDF file using the bindPdf method.
- Call the importBookmarksWithXml method.
- Save the updated PDF file using the save method.
The following code snippet shows how to import bookmarks from an XML file.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java | |
// Create PdfBookmarkEditor class | |
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor(); | |
// Open PDF file | |
bookmarkEditor.bindPdf("Input.pdf"); | |
// Import bookmarks | |
bookmarkEditor.importBookmarksWithXML("bookmarks.xml"); | |
// Save updated PDF file | |
bookmarkEditor.save("output.pdf"); |
From Aspose.PDF for Java 9.0.0, the PdfBookmarkEditor class implements the exportBookmarksToXML and importBookmarksWithXML methods with Stream arguments. As a result, extracted bookmarks can be imported from a stream object.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java | |
// Create PdfBookmarkEditor object | |
PdfBookmarkEditor bookmarkeditor = new PdfBookmarkEditor(); | |
// Open PDF file | |
bookmarkeditor.bindPdf("Input.pdf"); | |
InputStream is = new FileInputStream("bookmark.xml"); | |
bookmarkeditor.importBookmarksWithXML(is); | |
bookmarkeditor.save("output.pdf"); |