What is the best way to convert PDF bookmarks into a Table of content
on a PDF Page?
I know that you can add link annotations on a PDF Page but that is too
much complex in terms of giving exact co-ordinates etc for the TOC
lines. Plus need to take care of indentation and also dotted line
before printing page numbers.
Any help is appreciated.
Hi, i did that in the past like this:
- used pdftron to read the bookmarks to a list
- use that list as a data source for a rdlc client report. This way you can design the layout of the toc page and after that bind it to the list. For the dots i used a standard dornet graphics fu ction that calculates the physycal lengthof a string. Bases on this you can display thecorrevt numbee of dots between tje toc entry text and the page number.
If needed let me know nd i can provide you some code snippets from my project.
Here is a bit more high-level way to implement the same functionality:
Use PrintOutlineTree from Bookmarks sample (http://www.pdftron.com/pdfnet/samplecode.html#Bookmark) to traverse and extract bookmarks from an existing PDF.
To generate TOC layout, traverse Bookmarks and output HTML or XAML (e.g. as a string) then create a PDF page(s) from it using pdftron.PDF.Html2Pdf or Xaml2Pdf (for examples, see the corresponding samples - http://www.pdftron.com/pdfnet/samplecode.html).
Then traverse bookmark tree again using ‘pdftron.PDF.TextSearch’ to find the link positions (bbox, see TextSearch sample: http://www.pdftron.com/pdfnet/samplecode.html#TextSearch). You can use RegEx to include things such as dots etc.
For each match create a new link (you can use the same destination that you get from bookmark):
Annot link = Annot.CreateLink(doc bbox, bookmark.GetAction());
In case you need more low-level control, then using ElementBuilder/Writer (i.e. the above apprach in the previous post is more appropriate).