This is related to a previous question I asked about reading an annotation's appearance stream and writing its text to the Contents. I'd like to do a similar action with a Line annotation, reading its appearance width and setting the actual width to match the appearance.
I'm having trouble figuring out how to adapt my "set text contents using appearance" function to set line width. This is the code I'm currently using for getting the text:
//main function for setting inner content to appearance value
public void changeAnnotationContentToAppearance(PdfDictionary dict)
{
string surface = pdfTextParser.retrieveText(dict);
if (surface != null)
{
//update CONTENTS with appearance
//for changing line width, I would instead modify the /BS dictionary's /W key value, i think
dict.Put(PdfName.CONTENTS, new PdfString(surface));
}
}
//get text from /AP dictionary
public string retrieveText(PdfDictionary annotDictionary)
{
PdfDictionary appearancesDictionary = annotDictionary.GetAsDict(PdfName.AP);
foreach (PdfName key in appearancesDictionary.Keys)
{
PdfStream value = appearancesDictionary.GetAsStream(key);
if (value != null)
{
String text = ExtractAnnotationText(value);
return text;
}
}
return null;
}
//read the appearance stream and extract text contents
public String ExtractAnnotationText(PdfStream xObject)
{
PdfDictionary resources = xObject.GetAsDict(PdfName.RESOURCES);
ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();
PdfContentStreamProcessor processor = new PdfContentStreamProcessor(strategy);
processor.ProcessContent(ContentByteUtils.GetContentBytesFromContentObject(xObject), resources);
return strategy.GetResultantText();
}
ExtractAnnotationText()
only seems capable of reading text, not line width, because ITextExtractionStrategy()
doesn't have any methods for returning line properties. Does iTextSharp offer another extraction strategy for use in working with lines?
If I'm reading right, this question, this one, and this one suggest that I would need to implement a class, but I'm not sure which one I should subclass for getting line data, or how exactly I would go about doing that.
EDIT: I'd also like to get the appearance data for the points defining a rectangle in a textbox. Though this could be a different question, it seems closely related to this problem: retrieving non-text graphical data defining an annotation's appearance stream.