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

Free Support Forum - aspose.com

Unable to set backgroundColor of checkbox using DecorateField function

Hi,

I am using the following code to set the background color of all check boxes to white, and save the pdf to a tiff image.

It fails to set the background color of some check boxes, others it work fine.

I have attached the pdf file i am using. Any help will be greatly appreciated.

void Main()
{
string OriginalPdfPath = @“D:\test\ILJUV16.pdf”;
string destination = @“D:\test\ModifiedILJUV162.pdf”;
string pathToAsposeLicense = @“D:\test\Aspose.Pdf.lic”;
Stream licenseStream = new StreamReader(pathToAsposeLicense).BaseStream;
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(licenseStream);

Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(OriginalPdfPath);

Aspose.Pdf.Facades.FormEditor editor = new Aspose.Pdf.Facades.FormEditor(OriginalPdfPath , destination );
for (int page = 1; page <= editor.Document.Pages.Count; page++)
{
Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationCollection asposeAnnotation = editor.Document.Pages[page].Annotations;
for (int a = asposeAnnotation.Count; a >= 1; a–)
{
string fieldName = asposeAnnotation[a].FullName;
if (form.GetFieldType(fieldName) == Aspose.Pdf.Facades.FieldType.CheckBox
&& asposeAnnotation[a].Rect.ToRect().Height > 0)
{
editor.Facade = form.GetFieldFacade(fieldName);
editor.Facade.BackgroundColor = System.Drawing.Color.White;
editor.DecorateField(fieldName);
}
}
}

Aspose.Pdf.Facades.PdfConverter converter = new Aspose.Pdf.Facades.PdfConverter(editor.Document);
converter.SaveAsTIFF(@“d:\test\Output.tiff”);
}

Thanks,
Anwar

Hi Anthony,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample code and template file.

I am able to generate your mentioned issue after an initial test. Your issue has been registered in out issue tracking system with issue id: PDFNEWNET-34068. You will be notified via this forum thread regarding any updates against your issue.

Sorry for the inconvenience,

Hi Anthony,


Thanks for your patience.

I am pleased to share that the issue reported earlier has been resolved in latest release version of Aspose.Pdf for .NET 7.4.0. Also please replace editor.Facade = form.GetFieldFacade(fieldName); with editor.Facade = new FormFieldFacade(); in your code.

For your reference, I have also attached the resultant PDF and TIFF document for your reference.

Thanks for your help. Works fine now.