I have a PDF where the text shown in an annotation (as rendered in Adobe Reader) is different than what is given by its /Contents and /RC entries. This is related to the problem that I was dealing with in this question:
Can't change /Contents of annotation
In this case, instead of changing the appearance to match the annotation's contents, I want to do the opposite: get the appearance text and change the /Contents and /RC values to match. E.g., if the annotation displays "appearance" and /Contents 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't find where the appearance text 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 references to the fonts, but no contents. So it seems that the appearance stream doesn't include content data.
Other than /Contents and /RC, there doesn't seem to be anywhere in the annotation's data structure that stores content data. Where should I be looking for the appearance contents?