9 Answers, 1 is accepted
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.
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.
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 , 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?
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.
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.
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.
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.
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.
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.
Do you have any sample project, Which I can refer?
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).
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.