Hi,

I am trying to change links' destinations that I first retrieve from existing 
document by taking all the annotations from the page dictionary, and then if it 
is a link then replace its destination with a new one - let's say to point to a 
first page.

The issue I face is that it works quite well in the Adobe, but, Foxit Reader, 
for example, still reference to the old value, or other readers does not 
recognize this object any more as a link.

The code is the following: 

PdfReader reader=new PdfReader(@"C:\TestFile_Links.pdf");
reader.ConsolidateNamedDestinations();
Document doc=new Document(reader.GetPageSizeWithRotation(1));

Stream os = new FileStream(@"C:\TestFile_LinksChanged.pdf", 
FileMode.OpenOrCreate);
PdfCopy pdfCopy = new PdfCopy(doc, os);
doc.Open();

for (int i=1; i <= reader.NumberOfPages ;i++)
{
                PdfDictionary pageDic = reader.GetPageN(i);

                if (pageDic.Get(PdfName.ANNOTS) != null)
                {
                    PdfArray annotations = 
(PdfArray)PdfReader.GetPdfObject(pageDic.Get(PdfName.ANNOTS));
                    List<PdfObject> arrAnnot = annotations.ArrayList;

                    for (int j = 0; j < arrAnnot.Count; ++j)
                    {
                        PdfDictionary annotation = 
(PdfDictionary)PdfReader.GetPdfObjectRelease(arrAnnot[j]);
                        if 
(PdfName.LINK.Equals(annotation.Get(PdfName.SUBTYPE)))
                        {
                            annotation.Remove(PdfName.DEST);
                            annotation.PutEx(PdfName.DEST,  new 
PdfAction(PdfAction.FIRSTPAGE ));
                        }
                    }
                }

                pdfCopy .AddPage(pdfCopy .GetImportedPage(reader, i));
            }

pdfCopy .Close(); 

Can you maybe give me a hint if I'm doing anything wrong, or maybe this 
structure is changed, or links are broken? 

Thank you very much,
Vfeki
------------------------------------------------------------------------------
Systems Optimization Self Assessment
Improve efficiency and utilization of IT resources. Drive out cost and 
improve service delivery. Take 5 minutes to use this Systems Optimization 
Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to