既存のPDFファイルにXMLからブックマークをインポートする (facades)
Contents
[
Hide
]
importBookmarksWithXmlメソッドを使用すると、XMLファイルからPDFファイルにブックマークをインポートできます。
ブックマークをインポートするには:
- PdfBookmarkEditorオブジェクトを作成し、bindPdfメソッドを使用してPDFファイルをバインドします。
- importBookmarksWithXmlメソッドを呼び出します。
- saveメソッドを使用して更新されたPDFファイルを保存します。
以下のコードスニペットは、XMLファイルからブックマークをインポートする方法を示しています。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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、PdfBookmarkEditorクラスは、Stream引数を使用してexportBookmarksToXMLおよびimportBookmarksWithXMLメソッドを実装しています。その結果、抽出されたブックマークはストリームオブジェクトからインポートすることができます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |