PdfBookmarkEditor
Inheritance: java.lang.Object, com.aspose.pdf.facades.IVentureLicenseTarget, com.aspose.pdf.facades.Facade, com.aspose.pdf.facades.SaveableFacade
public final class PdfBookmarkEditor extends SaveableFacade
Represents a class to work with PDF file’s bookmarks including create, modify, export, import and delete.
Constructors
Constructor | Description |
---|---|
PdfBookmarkEditor() | Initializes new PdfBookmarkEditor object. |
PdfBookmarkEditor(IDocument document) | Initializes new PdfBookmarkEditor object on base of the document . |
Methods
Method | Description |
---|---|
createBookmarks() | Creates bookmarks for all pages. |
createBookmarkOfPage(String bookmarkName, int pageNumber) | Creates bookmark for the specified page. |
createBookmarks(Bookmark bookmark) | Creates the specified bookmark in the document. |
createBookmarks(Color color, boolean boldFlag, boolean italicFlag) | Create bookmarks for all pages with specified color and style (bold, italic). |
createBookmarkOfPage(String[] bookmarkName, int[] pageNumber) | Creates bookmarks for the specified pages. |
deleteBookmarks() | Deletes all bookmarks of the PDF document. |
deleteBookmarks(String title) | Deletes the bookmark of the PDF document. |
modifyBookmarks(String sTitle, String dTitle) | Modifys bookmark title according to the specified bookmark title. |
extractBookmarks() | Extracts bookmarks of all levels from the document. |
extractBookmarks(boolean upperLevel) | Extracts bookmarks of all levels from the document. |
extractBookmarks(String title) | Extracts the bookmarks with the specified title. |
extractBookmarks(Bookmark bookmark) | Extracts the children of a bookmark with a title like in specified bookamrk. |
extractBookmarksToHTML(String pdfFile, String cssFile) | Exports bookmarks to HTML file. |
exportBookmarksToXML(String xmlFile) | Exports bookmarks to XML file. |
exportBookmarksToXML(OutputStream output) | Exports bookmarks to XML stream. |
importBookmarksWithXML(String xmlFile) | Imports bookmarks to the document from XML file. |
importBookmarksWithXML(InputStream stream) | Imports bookmarks to the document from XML file. |
exportBookmarksToHtml(String inPdfFile, String outHtmlFile) | Exports bookmarks to HTML file. |
close() | Close the instance of PdfBookmarkEditor and release the resources. |
PdfBookmarkEditor()
public PdfBookmarkEditor()
Initializes new PdfBookmarkEditor object.
PdfBookmarkEditor(IDocument document)
public PdfBookmarkEditor(IDocument document)
Initializes new PdfBookmarkEditor object on base of the document .
Parameters:
Parameter | Type | Description |
---|---|---|
document | IDocument | Pdf document. |
createBookmarks()
public void createBookmarks()
Creates bookmarks for all pages.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.createBookmarks();
editor.save("example_out.pdf");
createBookmarkOfPage(String bookmarkName, int pageNumber)
public void createBookmarkOfPage(String bookmarkName, int pageNumber)
Creates bookmark for the specified page.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.createBookmarkOfPage("bookmark for page 1", 1);
editor.save("example_out.pdf");
Parameters:
Parameter | Type | Description |
---|---|---|
bookmarkName | java.lang.String | The specified bookmark name. |
pageNumber | int | The specified desination page. |
createBookmarks(Bookmark bookmark)
public void createBookmarks(Bookmark bookmark)
Creates the specified bookmark in the document. The method can be used for forming nested bookmarks hierarchy.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
Bookmark bm1=new Bookmark();
bm1.setPageNumber(1);
bm1.setTitle("First child");
Bookmark bm2=new Bookmark();
bm2.setPageNumber(2);
bm2.setTitle("Second child");
Bookmark bm=new Bookmark();
bm.setAction=(GoTo");
bm.setPageNumber(1);
bm.setTitle("Parent");
Bookmarks bms=new Bookmarks();
bms.add(bm1);
bms.add(bm2);
bm.setChildItem(bms);
editor.setCreateBookmarks(bm);
editor.save("example_out.pdf");
Parameters:
Parameter | Type | Description |
---|---|---|
bookmark | Bookmark | The bookmark will be added to the document. |
createBookmarks(Color color, boolean boldFlag, boolean italicFlag)
public void createBookmarks(Color color, boolean boldFlag, boolean italicFlag)
Create bookmarks for all pages with specified color and style (bold, italic).
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.createBookmarks(System.Drawing.Color.Red, true, true);
editor.save("example_out.pdf");
Parameters:
Parameter | Type | Description |
---|---|---|
color | java.awt.Color | The color of title. |
boldFlag | boolean | The flag of bold attribution. |
italicFlag | boolean | The flag of italic attribution. |
createBookmarkOfPage(String[] bookmarkName, int[] pageNumber)
public void createBookmarkOfPage(String[] bookmarkName, int[] pageNumber)
Creates bookmarks for the specified pages.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.createBookmarkOfPage("bookmark for page 1", 1);
editor.save("example_out.pdf");
Parameters:
Parameter | Type | Description |
---|---|---|
bookmarkName | java.lang.String[] | Bookmarks title array. |
pageNumber | int[] | Bookmarks desination page array. |
deleteBookmarks()
public void deleteBookmarks()
Deletes all bookmarks of the PDF document.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.deleteBookmarks();
editor.save("example_out.pdf");
deleteBookmarks(String title)
public void deleteBookmarks(String title)
Deletes the bookmark of the PDF document.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.deleteBookmarks("existing bookmark title");
editor.save("example_out.pdf");
Parameters:
Parameter | Type | Description |
---|---|---|
title | java.lang.String | The title of bookmark deleted. |
modifyBookmarks(String sTitle, String dTitle)
public void modifyBookmarks(String sTitle, String dTitle)
Modifys bookmark title according to the specified bookmark title.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.modifyBookmarks("existing bookmark title", "new bookmark title");
editor.save("example_out.pdf");
Parameters:
Parameter | Type | Description |
---|---|---|
sTitle | java.lang.String | Source bookmark title. |
dTitle | java.lang.String | Modified bookmark title. |
extractBookmarks()
public Bookmarks extractBookmarks()
Extracts bookmarks of all levels from the document.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
Bookmarks bms = editor.ExtractBookmarks();
for(Bookmark bm : bms)
System.out.println(bm.Title);
Returns: Bookmarks - The bookmarks collection of all bookmarks that exist in the document.
extractBookmarks(boolean upperLevel)
public Bookmarks extractBookmarks(boolean upperLevel)
Extracts bookmarks of all levels from the document.
Parameters:
Parameter | Type | Description |
---|---|---|
upperLevel | boolean | If true, extracts only upper level bookmarks. Else, extracts all bookmarks recursively. |
Returns: Bookmarks - List of extracted bookmarks.
extractBookmarks(String title)
public Bookmarks extractBookmarks(String title)
Extracts the bookmarks with the specified title.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
Bookmarks bms = editor.ExtractBookmarks("Title");
for(Bookmark bm : ```
(Iterable)
```bms)
System.out.println(bm.Title);
Parameters:
Parameter | Type | Description |
---|---|---|
title | java.lang.String | Extracted item title. |
Returns: Bookmarks - Bookmark object collection has items with the same title.
extractBookmarks(Bookmark bookmark)
public Bookmarks extractBookmarks(Bookmark bookmark)
Extracts the children of a bookmark with a title like in specified bookamrk.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
Bookmark bookmark = new Bookmark();
bookmark.setTitle ( "Title");
Bookmarks bms = editor.ExtractBookmarks(bookmark);
for(Bookmark bm : ```
(Iterable)
```bms)
System.out.println(bm.Title);
Parameters:
Parameter | Type | Description |
---|---|---|
bookmark | Bookmark | The specified bookamrk. |
Returns: Bookmarks - Bookmark collection with child bookmarks.
extractBookmarksToHTML(String pdfFile, String cssFile)
public void extractBookmarksToHTML(String pdfFile, String cssFile)
Exports bookmarks to HTML file.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.extractBookmarksToHTML("example.pdf", null);
Parameters:
Parameter | Type | Description |
---|---|---|
pdfFile | java.lang.String | The PDF file which bookmarks will be exported. |
cssFile | java.lang.String | The CSS file to display HTML file, can be null. |
exportBookmarksToXML(String xmlFile)
public void exportBookmarksToXML(String xmlFile)
Exports bookmarks to XML file.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.exportBookmarksToXML("bookmarks.xml");
Parameters:
Parameter | Type | Description |
---|---|---|
xmlFile | java.lang.String | The output XML file. |
exportBookmarksToXML(OutputStream output)
public void exportBookmarksToXML(OutputStream output)
Exports bookmarks to XML stream.
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.io.OutputStream | Output stream where data will be stored. |
importBookmarksWithXML(String xmlFile)
public void importBookmarksWithXML(String xmlFile)
Imports bookmarks to the document from XML file.
PdfBookmarkEditor editor = new PdfBookmarkEditor();
editor.bindPdf("example.pdf");
editor.importBookmarksWithXML("bookmarks.xml");
editor.save("example_out.pdf");
Parameters:
Parameter | Type | Description |
---|---|---|
xmlFile | java.lang.String | The XML file containing bookmarks list. |
importBookmarksWithXML(InputStream stream)
public void importBookmarksWithXML(InputStream stream)
Imports bookmarks to the document from XML file.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | Stream with bookmarks data. |
exportBookmarksToHtml(String inPdfFile, String outHtmlFile)
public static void exportBookmarksToHtml(String inPdfFile, String outHtmlFile)
Exports bookmarks to HTML file.
PdfBookmarkEditor.extractBookmarksToHTML("example.pdf", "bookmarks.html");
Parameters:
Parameter | Type | Description |
---|---|---|
inPdfFile | java.lang.String | Input PDF file which bookmarks will be exported. |
outHtmlFile | java.lang.String | Output HTML file |
close()
public void close()
Close the instance of PdfBookmarkEditor and release the resources.