I'm working on a project where i have to read an existing pdf using iTextSharp.PdfReader, then getAnnotations in order to insert them back in a new generated pdf.
My problem is that i managed to get Annotations from the input pdf, but i can't find the annotation details (such as destination page number, Action..), for now, i did found RECT, DEST, SUBTYPE, but the other one are null
Code to get annotation :
for (int i = 1; i <= pagesNbr; i++)
{
iTextSharp.text.pdf.PdfReader read = new iTextSharp.text.pdf.PdfReader("TEST_mod.pdf");
iTextSharp.text.pdf.PdfDictionary pageDict = read.GetPageN(i);
iTextSharp.text.pdf.PdfArray annotArray = pageDict.GetAsArray(iTextSharp.text.pdf.PdfName.ANNOTS);
for (int j = 0; j < annotArray.Size; ++j)
{
iTextSharp.text.pdf.PdfDictionary curAnnot = annotArray.GetAsDict(j);
foreach (iTextSharp.text.pdf.PdfObject A in annotArray.ArrayList)
{
iTextSharp.text.pdf.PdfDictionary AnnotationDictionary = (iTextSharp.text.pdf.PdfDictionary)iTextSharp.text.pdf.PdfReader.GetPdfObject(A);
sw.WriteLine("\n ANNOTS pour la page n°: "+i+"\n");
sw.WriteLine(AnnotationDictionary.Get(iTextSharp.text.pdf.PdfName.TYPE));
sw.WriteLine(AnnotationDictionary.Get(iTextSharp.text.pdf.PdfName.SUBTYPE));
sw.WriteLine(AnnotationDictionary.Get(iTextSharp.text.pdf.PdfName.RECT));
sw.WriteLine(AnnotationDictionary.Get(iTextSharp.text.pdf.PdfName.BORDER));
sw.WriteLine(AnnotationDictionary.Get(iTextSharp.text.pdf.PdfName.DEST));
}
}
}
My other problem, is how to re insert them in my new generated pdf, after getting them of course, For now im using this code only to test if i can really insert an annoation manually
public void setAnnots(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Rectangle linkLocation,PdfDestination destination,int destPage)
{
PdfAnnotation link = PdfAnnotation.CreateLink(
writer,
linkLocation,
PdfAnnotation.HIGHLIGHT_INVERT,
destPage, destination);
writer.AddAnnotation(link);
}
Please can anyone help me solve this problem, thanks in advance.