I am using iTextSharp library and C#.Net for splitting my PDF file.
Consider a PDF file named sample.pdf containing 72 pages. This sample.pdf contains pages that have hyperlink that navigate to other page. Eg: In the page 4 there are three hyperlinks which when clicked navigates to corresponding 24th,27th,28th page. As same as the 4th page there are nearly 12 pages that is having this hyperlinks with them.
Now using iTextSharp library I had split this PDF pages into 72 separate file and saved with the name as 1.pdf,2.pdf....72.pdf. So in the 4.pdf when clicking that hyperlinks I need to make the PDF navigate to 24.pdf,27.pdf,28.pdf.
Please help me out here. How can I edit and set the hyperlinks in the 4.pdf so that it navigates to corresponding pdf files.
Thank you, Ashok
What you want is quite possible. What you want will require you to work with the low-level PDF objects (PdfDictionary, PdfArray, etc).
And whenever someone needs to work with those objects, I always refer them to the PDF Reference. In your case, you'll want to examine chapter 7 (particularly section 3) and chapter 12, sections 3 (doc-level navigation) and 5 (annotations).
Assuming you've read that, here's what you need to do:
Step 1.1 isn't simple. There are several different kinds of "local goto" annotation formats. You need to determine which page a given link points to. Some links might say the PDF equivalent of "next page" or "previous page", while others will include a reference to a particular page. This will be an "indirect object reference", not a page number.
To determine the page number from a page reference, you need to... ouch. Okay. The most efficient way would be to call PdfReader.GetPageRef(int pageNum) for each page in the original document and cache it in a map (reference->pageNum).
You can then build "remote goto" links by creating a remote goto PdfAction, and writing that into the link annotation's "A" (action) entry, removing anything that was there before (probably a "Dest").
I don't speak C# very well, so I'll leave the actual implementation to you.
This function below uses iTextSharp to:
Step #4 is to insert whatever logic you want in here... update the links, log them, etc.
Good luck.
Alright, based on what @Mark Storer here's some starter code. The first method creates a sample PDF with 10 pages and some links on the first page that jump around to different parts of the PDF so we have something to work with. The second methods opens the PDF created in the first method and walks through each annotation trying to figure out which page the annotation links to and outputs it to the TRACE window. The code is in VB but should be easily converted to C# if needed. Its targetting iTextSharp 5.1.1.0.
If I get a chance I might try to take this further and actually split and re-link things but I don't have time right now.