This article describes how to create bookmarks in PDF using C#. It has all the details to set the IDE, a list of steps, and a sample code to bookmark a PDF with C#. You will learn different techniques to add a bookmark to a single page or all the pages in the PDF or format the bookmarks.
Steps to Add Bookmarks to PDF using C#
- Set the environment to use Aspose.PDF for .NET to add Bookmarks
- Instantiate the PdfBookmarkEditor to work with bookmarks in a PDF
- Bind the PDF file to the editor
- Define an array of bookmark titles corresponding to specific pages
- Define an array of page numbers for the respective bookmarks
- Create bookmarks for the specified pages using the titles
- Save the updated PDF with the bookmarks to a new file
These steps explain how to add a bookmark in PDF using C#. Instantiate the PdfBookmarkEditor class object, bind the PDF file with this editor, and define an array of bookmark titles and corresponding page numbers. Finally, call the CreateBookmarkOfPage to create bookmarks and save the output.
Code to Bookmark PDF Document using C#
This code demonstrates how to insert bookmark in PDF using C#. You can create a bookmark for a single page using another overload of the CreateBookmarkOfPage() method by passing the bookmark name and PDF page number; for creating bookmarks on all the pages, use the CreateBookmarks() method, and for setting the formatting of bookmarks, use the different overload of the CreateBookmarks() method by providing the color, bold flag and Italic flag. You can add a duplicate bookmark for a single page using the CreateBookmarks() method using the Bookmark class object.
This quick tutorial has guided us to bookmark a PDF. For removing background from a PDF, refer to the article on Remove background from PDF using C#.