We have found a couple of issues with flattening free text annotations. We have a process that takes in uploaded PDF documents that can include annotations. We do some processing and when we are done, we need to flatten all annotations. We are having some issues with text annotations.
First, we get documents with free text annotations where the Default Appearance is set as an encoded string, but that have no appearance dictionary. These annotations render correctly in Adobe Reader. When we flatten these annotations, it seems that Aspose uses the TextStyle property which gets initialized with some default values (Helvetica, 12pt). This causes the annotation to appear to change from the source. We’re working around this by manually setting the TextStyle to be the DefaultAppearance (see code below) but I have no idea if that’s a good long-term workaround. It also produced another error that I’ll detail below. I’ve attached an example PDF (annotation with no appearance dictionary.pdf)
if (annotation is FreeTextAnnotation)
{
var fta = annotation as FreeTextAnnotation;
if (!String.IsNullOrEmpty(fta.Contents))
{
fta.TextStyle.FontSize = fta.DefaultAppearanceObject.FontSize;
fta.TextStyle.FontName = fta.DefaultAppearanceObject.FontName;
fta.TextStyle.Color = fta.DefaultAppearanceObject.TextColor;
}
}
Second, we sometimes get an IndexOutOfRangeException when setting TextStyle.FontSize on an annotation. This appears to have to do with a text annotation with a 0 area bounding rectangle and empty contents. I have attached a sample PDF (no length annotation.pdf) with this type of annotation. This may not be a valid annotation, but we have little control over the state of the incoming documents to our application and Adobe Reader is able to render it. We are filtering out these text annotations for now.