We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to set background colour of a FreeTextAnnotation

Is it possible to set the background colour of a FreeTextAnnotation? I can set the font colour through the DefaultAppearance but I’m struggling to set the background colour.


Pdf.InteractiveFeatures.DefaultAppearance appearance =
    new Pdf.InteractiveFeatures.DefaultAppearance(“Arial”, fontSize, color);

Pdf.InteractiveFeatures.Annotations.FreeTextAnnotation annotation =
new Pdf.InteractiveFeatures.Annotations.FreeTextAnnotation(page, new Pdf.Rectangle(llx, lly, urx, ury), appearance);


TIA
Dan

Hi Dan,


Thanks for contacting support.

Please use following sample code to set the background color of a FreeTextAnnotation. I have also attached the output PDF document for your reference.

C#

// Open document
Document pdfDocument = new Document(dataDir + “SetFreeTextAnnotationFormatting.pdf”);
// Instantiate DefaultAppearance object
DefaultAppearance default_appearance = new DefaultAppearance(“Arial”, 28, System.Drawing.Color.Red);
// Create annotation
FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance);
freetext.Color = Aspose.Pdf.Color.Aqua;
freetext.Opacity = .7f;
// Specify the contents of annotation
freetext.Contents = “Free Text”;
// Add anootation to annotations collection of page
pdfDocument.Pages[1].Annotations.Add(freetext);
dataDir = dataDir + “SetFreeTextAnnotationFormatting_out.pdf”;
// Save the updated document
pdfDocument.Save(dataDir);

If you still face any issue, please feel free to contact us.

Best Regards,

Ah, I had tried the Color property but it hadn’t worked for me - I now see that it will show but only if I activate the annotation by double-clicking it. Does yours work because there is no existing background perhaps? Compare with my attached example annotated with your code.


Thanks

Dan

Hi Dan,


I have tested with your file using above sample code and I didn’t had to double click on the annotation to see the background color. I have attached the output PDF document for your reference. I am using Aspose.Pdf for .NET 17.2.0 , please confirm which version of Aspose.Pdf you are using. I will appreciate if you share you sample project, It will help us to understand the issue and replicate it on our environment.

We are sorry for the inconvenience.

Best Regards,

I seem to have only 8.4.1 but on investigation we are only licensed up to 8.8.0 (which gives the same behaviour) so I think we are going to have to live with it.


Thank you

Dan

Hi Dan,

Before you upgrade your license subscription, you may consider downloading latest release of Aspose.Pdf for .NET 17.2.0 and request to Get a temporary license to test the release without any limitations.

Should you have any further query, please feel free to contact.