Pdfium fillform and check on checkbox

I am trying to enable check using pdfium.

Below is my code to enable checkbox in pdfium acroform.

 int pageCount = FPDF_GetPageCount(doc);
    for (int i = 0; i < pageCount; ++i) {
        FPDF_PAGE page = FPDF_LoadPage(doc, i);
        FORM_OnAfterLoadPage(page, form); // Must call after loading the page
        FORM_DoPageAAction(page, form,FPDFPAGE_AACTION_OPEN); // Trigger any page actions
            
        int annotCount = FPDFPage_GetAnnotCount(page);
        for (int j = 0; j < annotCount; ++j) {
            FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, j);
            if (FPDFAnnot_GetSubtype(annot) == FPDF_ANNOT_WIDGET) {
                int fieldType = FPDFAnnot_GetFormFieldType(form, annot);
                if (fieldType == FPDF_FORMFIELD_CHECKBOX) {
                    FPDFAnnot_SetStringValue(annot, "V", GetFPDFWideString("Yes"));
                    FPDFAnnot_SetAP(annot, FPDF_ANNOT_APPEARANCEMODE_NORMAL, nullptr);
                }
            }
            
            FPDFPage_CloseAnnot(annot);
        }
        FORM_OnBeforeClosePage(page, form);
        FPDF_ClosePage(page);
    }

On editing PDF & checking details, I see the dictionary value is expected in format. How to achieve it. Also How to set appearance stream along with set value? /V /Off /V /Yes

I tried code posted above and I am not seeing checkbox enabled in pdf

Upvotes: 0

Views: 37

Answers (0)

Related Questions