FreeText annotation

Hi,

I am using PDFTron to generate some FreeText annotations in one of our programs.

I use the following code:

pdftron.PDF.Annots.FreeText txt = pdftron.PDF.Annots.FreeText.Create( m_PdfDocument.GetSDFDoc(), pos );

txt.SetAppearance( CreateMyAppearance( m_PdfDocument, annotation, pos));

txt.SetContents( annotationText );
txt.SetBorderStyle( new Annot.BorderStyle( Annot.BorderStyle.Style.e_solid, 0 ) );

this.GetDefaultAnnotation( “FreeText” ).SetColor( new ColorPt( 0, 0, 1 ) );

pag.AnnotPushBack( txt );

The problem is when I resize the annotation using the “Edit” toolmode, it changes color to red and the “Appearance stream” appears to be lost.

This line appears to do nothing:

this.GetDefaultAnnotation( “FreeText” ).SetColor( new ColorPt( 0, 0, 1 ) );

How can i retain the original “Appearance” ?

Kind regards,

Tom Staelens
Sensotec Belgium

Hi Tom,

If you generate a custom appearance there is no way for PDFNet to regenerate that appearance (e.g. when annotation is scalled), since it does not know how you build the appearance.

At the same time since you customization seems to be small (just a color change) you may be able to chage the default appearance by changing the “DA” (Default Appearance) string in annotation dictionary for FreeText annotation:

annot.GetSDFObj().PutString(“DA”, "/Arial 12 Tf 0 0 1 rg ");

For more info plase see:
https://groups.google.com/d/topic/pdfnet-sdk/bNO73SNojEM/discussion

Please note that although this article talks about form fields, the same applies to FreeText annotation since it also supports DA entry (Table 174 in ISO 32000 PDF spec).

While the previous post works for built in fonts, if you want to use a font registered with the OS, then the following code will do this. If you want to use a completely custom font, then you would just replace the Font.Create call with the one matching the font file you want to load, and use the explicit font path. Or, use the PDFNet.AddFontSubst API to override system font loading.

// Create font and add to annotations DR/Fonts entry
string fontDRName = "F0"; // arbitrary ID
Font font = Font.Create(mPDFView.GetDoc(), "Comic Sans", textAnnot.GetContents());

Obj annotObj = textAnnot.GetSDFObj();
Obj drDict = annotObj.PutDict("DR");
Obj fontDict = drDict.PutDict("Font");
fontDict.Put(fontDRName, font.GetSDFObj());

textAnnot.GetSDFObj().PutString("DA", String.Format("/{0} 12 Tf 0 0 1 rg ", fontDRName));

textAnnot.RefreshAppearance();