This is a migrated thread and some comments may be shown as answers.

Create a PDF Index Page with Links?

9 Answers 150 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 14 Jul 2015, 11:39 PM

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... ?

9 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 17 Jul 2015, 10:43 AM
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
Suren
Top achievements
Rank 1
commented on 21 Jul 2021, 07:19 AM

HI Petya , do you have any C# sample code(fully) ? if yes please send me too.. i need to combine few pdf document and create index page. when clicking the index page then need to focus to relevant page.
0
Dan
Top achievements
Rank 1
answered on 19 Jul 2015, 01:12 AM

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?

0
Petya
Telerik team
answered on 22 Jul 2015, 10:33 AM
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
0
Dan
Top achievements
Rank 1
answered on 22 Jul 2015, 02:27 PM

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.

 

0
Petya
Telerik team
answered on 27 Jul 2015, 07:48 AM
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
0
Johnathan
Top achievements
Rank 1
answered on 25 May 2016, 01:43 PM

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

0
Petya
Telerik team
answered on 30 May 2016, 10:14 AM
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
0
Chirag
Top achievements
Rank 1
answered on 03 Apr 2018, 01:39 PM

Hi Petya,

Do you have any sample project, Which I can refer?  

Suren
Top achievements
Rank 1
commented on 21 Jul 2021, 07:15 AM

HI Petya , do you have any C# sample code(fully) ? if yes please send me too.. i need to combine few pdf document and create index page. when clicking the index page then need to focus to relevant page.
0
Martin
Telerik team
answered on 22 Jul 2021, 10:04 AM

A sample example of how to create a Table of Contents (TOC) page with links leading to the relevant pages could be found in the following feature request: PdfProcessing: Provide API for inserting Table of Contents (TOC).

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing
Asked by
Dan
Top achievements
Rank 1
Answers by
Petya
Telerik team
Dan
Top achievements
Rank 1
Johnathan
Top achievements
Rank 1
Chirag
Top achievements
Rank 1
Martin
Telerik team
Share this question
or