Create a PDF Index Page with Links?

8 posts, 0 answers
  1. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 14 Jul 2015 Link to this post

    Is it possible to create an index page with bookmarks to various other pages.  For example

     

    PDF TITLE

    1. Background

    2. Contents

    3. Summary

     

    Where click on 1 would go to Page 5, click on 2 would go to page 10, etc... ?

  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 17 Jul 2015 Link to this post

    Hello Dan,

    You can take advantage of the Annotations and Destinations functionality to achieve such result. Take a look at the below snippet that will add a link at the top-left corner of the first page which will scroll the document to the second page.
    Location location = new Location();
    location.Left = 0;
    location.Top = 0;
    location.Page = document.Pages[1];
     
    var link = document.Pages[0].Annotations.AddLink(location);
    link.Rect = new Rect(10, 10, 50, 50);

    Note, however, that at this point the RadFlowDocumentEditor doesn't expose convenient API that will allow you to find where a specific element (text fragment) is positioned, You could take a look at the Block article for an alternative approach to creating documents which will allow to measure each block and obtain its size for the purposes of creating the link's rectangle.

    I hope this is helpful.

    Regards,
    Petya
    Telerik
  3. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 18 Jul 2015 in reply to Petya Link to this post

    Thank you!

    I was able to implement this, but have another question.  Here is my flow right now:

    Loop through and create a multi-section report.  Each report is a Table, using InsertTable because I don't know how many pages each will be.  As I loop through I keep track of the page indexes at each section break and descriptions I have set for each section.

    Once the entire report is written, I then insert a new page at position [0], draw a table with my table of contents, insert the Annotations as you have show above - and use the Block.Measure method to position the .rect in the right spot.  

    Finally I use the RadContentEditor's ​Position and DrawTable to insert my table of contents.

    The potential problem is if my table is too long to fit on one page....  So now my question.  If I create the table of contents in a separate RadFixedDocument so I can use InsertTable...  Can I then insert the pages from that Document into the top of my first document?  If so - how would I do that?  If not - is there another way to accomplish this?

  4. Petya
    Admin
    Petya avatar
    975 posts

    Posted 22 Jul 2015 Link to this post

    Hi Dan,

    I'm glad to hear my suggestion helped you.

    As to the problem at hand, I think the best option would be to create separate RadFixedDocument instances and merge them together. In fact, in Q2 2015 we introduced a Merge() method that will remove all pages and associated document information (like annotations and destinations) from one document and move it to the other.
    target.Merge(source);

    Note that the method literally moves the pages, meaning that even if the table of contents is one and a half pages long, the rest of the content will not start on the second page, but on the third one.

    Let me know how this works for you.

    Regards,
    Petya
    Telerik
  5. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 22 Jul 2015 in reply to Petya Link to this post

    I was able to get this working by building the two RadFixedDocument's then inserting the Table of Contents document a page at a time into the main document. I found this works so long as I first remove the page from the source RadFixedDocument before inserting it into the target RadFixedDocument.

    I will play around with the Merge next - that sounds like a better way.

     

  6. Petya
    Admin
    Petya avatar
    975 posts

    Posted 27 Jul 2015 Link to this post

    Hello Dan,

    Actually, that's precisely what the Merge() method does - it removes the pages from one document and adds them to the other. The only additional thing is that it also copies the document-specific information like annotations.

    This is handy when the documents you want to merge are external, i.e. they are created with another approach/software and are only imported with RadPdfProcessing. In the case that you're generating the documents yourself, however, simply moving the pages seems sufficient.

    Regards,
    Petya
    Telerik
  7. Johnathan
    Johnathan avatar
    32 posts
    Member since:
    Sep 2012

    Posted 25 May in reply to Petya Link to this post

    Hi Petya,

    I have a similar question related to this topic. I need the ability to add header & footer images to an existing PDF document before merging it with a PDF document that I created using the Telerik PDF processing assemblies. Is this possible?

    I know that there are no existing references to headers & footers in the PDF processing assemblies, but I was hoping that I could possibly modify each PDF page to insert the header & footer images manually somehow. Any help on this would be greatly appreciated.

    Thanks,

    Johnathan

  8. Petya
    Admin
    Petya avatar
    975 posts

    Posted 30 May Link to this post

    Hello Johnathan,

    I'd suggest using the FixedContentEditor utility class for this task. It works over a fixed page instance and allows you to add elements and position them precisely where you want. Please have a look at this resources:
    - The Using PdfFormatProvider help topic shows how you can import a PDF document to a RadFixedDocument instance.
    FixedContentEditor gives the ability to insert elements in a page and position them.
    - The Position article elaborates on the available API for positioning fixed elements.

    I hope this helps.

    Regards,
    Petya
    Telerik
Back to Top