1

I was wondering of how to get total number of bookmarks in a pdf file. I am reading pdf files as:

pdfReader = new iTextSharp.text.pdf.PdfReader(filePath);

I know I have to use pdfOutline class, but how to use it in my current scenario is my question.

Assad Nazar
  • 1,420
  • 5
  • 20
  • 40

2 Answers2

1

Well, I figured out myself. Following is the method, you can use to get the total number of bookmarks within a PDF file.

int bookmarks = iTextSharp.text.pdf.SimpleBookmark.GetBookmark(pdfReader).Count;

Hope it will help someone, somewhere.

Assad Nazar
  • 1,420
  • 5
  • 20
  • 40
0

Your answer is misleading because it will only get the TOP level (Root) Bookmarks. This is not the same as total number of Bookmarks. PDF Bookmarks work like a Tree or XML Structure with nested objects. Your suggested answer will miss them all.

Here is the proper code to resursively find all bookmarks and do something with them https://stackoverflow.com/a/28634840/2772858

Hakan Usakli
  • 492
  • 5
  • 11