I have a PDF where the text shown in the annotation (as shown in Adobe Reader) is different from the text specified in its / Contents and / RC . This is due to the problem I encountered in this question:
Unable to edit / Annotation content
In this case, instead of changing the appearance in accordance with the contents of the annotation, I want to do the opposite: get the text of the appearance and change the / Content and / RC values to match. For example, if the annotation displays “appearance” and / Content is set to “content”, I want to do something like:
void setContent(PdfDictionary dict)
{
PdfString str = dict.GetAsString(new PdfName("KeyForAppearanceText"));
dict.Put(PdfName.CONTENTS,str);
}
But I can not find where the text of the appearance is stored. I got the dictionary referenced by / AP with this code:
private PdfDictionary getAPAnnot(PdfArray annotArray,PdfDictionary annot)
{
PdfDictionary apDict = annot.GetAsDict(PdfName.AP);
if (apDict!=null)
{
PdfIndirectReference ap = (PdfIndirectReference)apDict.Get(PdfName.N);
PdfDictionary apRefDict = (PdfDictionary)pdfController.pdfReader.GetPdfObject(ap.Number);
return apRefDict;
}
else
{
return null;
}
}
This dictionary has the following hashMap:
{[/BBox, [-38.7578, -144.058, 62.0222, 1]]}
{[/Filter, /FlateDecode]}
{[/Length, 172]}
{[/Matrix, [1, 0, 0, 1, 0, 0]]}
{[/Resources, Dictionary]}
/ Resources has indirect links to fonts, but without content. Thus, it seems that the appearance stream does not include content data.
Other than / Content and / RC , it looks like there should be nothing in the annotation data structure that stores content data. Where should I look for the contents of the look?