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

ConstructorDescription
PdfBookmarkEditor()Initializes new PdfBookmarkEditor object.
PdfBookmarkEditor(IDocument document)Initializes new PdfBookmarkEditor object on base of the document .

Methods

MethodDescription
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:

ParameterTypeDescription
documentIDocumentPdf 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:

ParameterTypeDescription
bookmarkNamejava.lang.StringThe specified bookmark name.
pageNumberintThe 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:

ParameterTypeDescription
bookmarkBookmarkThe 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:

ParameterTypeDescription
colorjava.awt.ColorThe color of title.
boldFlagbooleanThe flag of bold attribution.
italicFlagbooleanThe 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:

ParameterTypeDescription
bookmarkNamejava.lang.String[]Bookmarks title array.
pageNumberint[]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:

ParameterTypeDescription
titlejava.lang.StringThe 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:

ParameterTypeDescription
sTitlejava.lang.StringSource bookmark title.
dTitlejava.lang.StringModified 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:

ParameterTypeDescription
upperLevelbooleanIf 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:

ParameterTypeDescription
titlejava.lang.StringExtracted 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:

ParameterTypeDescription
bookmarkBookmarkThe 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:

ParameterTypeDescription
pdfFilejava.lang.StringThe PDF file which bookmarks will be exported.
cssFilejava.lang.StringThe 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:

ParameterTypeDescription
xmlFilejava.lang.StringThe output XML file.

exportBookmarksToXML(OutputStream output)

public void exportBookmarksToXML(OutputStream output)

Exports bookmarks to XML stream.

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamOutput 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:

ParameterTypeDescription
xmlFilejava.lang.StringThe XML file containing bookmarks list.

importBookmarksWithXML(InputStream stream)

public void importBookmarksWithXML(InputStream stream)

Imports bookmarks to the document from XML file.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamStream 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:

ParameterTypeDescription
inPdfFilejava.lang.StringInput PDF file which bookmarks will be exported.
outHtmlFilejava.lang.StringOutput HTML file

close()

public void close()

Close the instance of PdfBookmarkEditor and release the resources.