0

I've just downloaded iTextSharp and before I put a lot of effort into this I'd like to know if this scenario is possible with it. We have a client that is insisting that their SSRS report PDFs contain a table of contents, preferably with page numbers. The various components of these reports have highly variable lengths so we can't hard code actual page numbers. As you all probably know, there is no direct way to create a Table of Contents in SSRS. (We've even had a special session with the Microsoft rep about this.)

What I would like to do is as follows:

  • Mark the target locations in the SSRS report by setting their DocumentMapLabel property.

  • Generate the pdf in the usual fashion, either from the report server or a ReportViewer control. (This will be in c#.)

  • Open the pdf in my hypothetical code.

  • Insert a blank page at or near the front.

  • Scan the pdf for DocumentMapLabels (and, ideally, detect which page
    they're on.)

  • Populate the blank page with links to the various sections.

Is this possible?

1 Answers1

0

I wouldn't use your design. As soon as the TOC needs more than one page, you're in trouble. Maybe you're confident that this won't happen today, but what if that's needed tomorrow?

You have different options:

  1. Create your document in one go. Add the TOC at the end. Reorder the pages before closing the document.
  2. Create a document (e.g. in memory) using named destinations for the targets. Create a document (e.g. in memory) with the TOC referring to the named destinations. Merge the two documents into one document, consolidating the named destinations.
  3. Create a document with bookmarks (this will result in a bookmarks panel to the left in Adobe Reader). Then read the bookmarks to create a TOC in PDF and merge the PDF with the TOC with the document that has the bookmarks.

All of this is documented.

In The Best iText Questions on StackOverflow, you'll find the answers to these (and many other) questions:

What you want to do is possible, but not the way you describe it. Read the book, pick an option and post a new question if you have a problem with the option you picked. Just download that book; it's free of charge.

Note: iText(Sharp) is free software, NOT freeware. This means that it is only free of charge if you agree with the open source license (the AGPL). It is not free of charge in all situations as explained in this video. That's also important to know before you start an iText(Sharp) project.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Thank you for your prompt response and all the links! – user2996466 Jul 01 '15 at 17:10
  • @user2996466 Welcome on StackOverflow. If the answer was helpful, please accept it and/or upvote it. Only then can the answer be used for further reference (e.g. when somebody posts a duplicate question). – Bruno Lowagie Jul 02 '15 at 05:56