It seems that it's not possible with the current public pdfium interface.
According to the manual (pp. 615,
https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf); the way to check/uncheck a checkbox is to set /AS value (in annot dict) to match the dict entry in /AP -> /N; which in turn defines how a checked / unchecked box looks like. Apparently, the /Off value is the default for an unselected checkbox option (in /AP -> /N). Yet, there is no standard on how the checked dict entry should be called: I've seen different names within the same form multiple times. This means that the way to set the checkbox implies the following steps:
- Get the /Off and /<something else> options from the /AP -> /N dict from the annot
- Set the /AS to match <something else>
In fact, this is exactly what is done by the C++ code, `CPDFSDK_Widget::SetCheck(bool bChecked)` is a function (not public) that given a checkbox / radio button widget sets the value to `bChecked`. Indeed, the function calls the following that does the job:
void CPDF_FormControl::CheckControl(bool bChecked) {
DCHECK(GetType() == CPDF_FormField::kCheckBox ||
GetType() == CPDF_FormField::kRadioButton);
ByteString csOldAS = m_pWidgetDict->GetByteStringFor("AS", "Off");
ByteString csAS = "Off";
if (bChecked)
csAS = GetOnStateName();
if (csOldAS == csAS)
return;
m_pWidgetDict->SetNewFor<CPDF_Name>("AS", csAS);
}
All this being said, we don't have any exported function that would set the CPDF_Name for a dict. We can only set CPDF_String values, which wraps the string in parenthesis which signals the PDF that it should be treated as a string and not as dict value.
If time allows, I might open a CL to pdfium so we can have some function as FPDFAnnot_SetChecked function for this case. I managed to get it working but I'm missing the tests and it would require compiling pdfium and not relying on the official binaries.
All the best!