PDF checkbox color not working

Hi,

I am trying to change the default checkbox tick colour in a downloading PDF file but the tick colour is always black. Any thought please?


Please refer to my code snippet below 


loadedDocument.Form.Fields.TryGetField(field, out PdfLoadedField loadedField);

var sf = loadedField as PdfLoadedCheckBoxField;

sf.ForeColor = new PdfColor(Color.Blue);

sf.BorderColor = new PdfColor(Color.Blue);

sf.BackColor = new PdfColor(Color.Blue);

sf.Checked = true;



3 Replies

GK Gowthamraj Kumar Syncfusion Team October 26, 2021 08:16 AM UTC

Hi James, 
 
Thank you for contacting Syncfusion support.

Yes. We can change the check box tick color by using ForeColor property of PdfLoadedCheckBoxField class in our PDF library. We have shared the sample and output document for your requirement, please try the sample on your end and let us know the result.

Sample: https://www.syncfusion.com/downloads/support/forum/169898/ze/ConsoleSample-2130720228
 
 
Please find the below code snippet to add image in signature field, 
//Load the PDF document 
FileStream docStream = new FileStream("../../../Checkbox1.Pdf", FileMode.Open, FileAccess.Read); 
 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); 
 
//Get the loaded form. 
PdfLoadedForm loadedForm = loadedDocument.Form; 
 
loadedForm.SetDefaultAppearance(false); 
//load the check box from field collection 
 
PdfLoadedCheckBoxField loadedCheckBoxField = loadedForm.Fields[0] as PdfLoadedCheckBoxField; 
 
// fill the checkbox forecolor 
loadedCheckBoxField.ForeColor = new PdfColor(Color.Blue); 
 
//load the check box from field collection 
PdfLoadedCheckBoxField loadedCheckBoxField1 = loadedForm.Fields[1] as PdfLoadedCheckBoxField; 
 
// fill the checkbox forecolor. 
loadedCheckBoxField1.ForeColor = new PdfColor(Color.Red); 
loadedCheckBoxField1.Checked = true; 

//Save the document into stream. 
MemoryStream stream = new MemoryStream(); 
loadedDocument.Save(stream); 
stream.Position = 0; 
 
//Close the document. 
loadedDocument.Close(true); 
             
  
Please refer the below documentation for more information,
UG:
https://help.syncfusion.com/file-formats/pdf/working-with-forms#filling-the-check-box-field  

Please let us know if you need any further assistance with this. 

Regards,
 
Gowthamraj K 



JA James replied to Gowthamraj Kumar October 26, 2021 10:10 AM UTC

Thank you Gowthamraj.


It's solved by adding

loadedForm.SetDefaultAppearance(false);



GK Gowthamraj Kumar Syncfusion Team October 26, 2021 10:51 AM UTC

Hi James, 
 
Thank you for your update. We are glad to know that your problem has been solved. 
 
Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon