corymickelson / CommonPdf

Pdf utility library
16 stars 5 forks source link

Checkboxes won't check #16

Open dannymcpherson opened 6 years ago

dannymcpherson commented 6 years ago

To work around it, I commented out this if-block in fdf-generator:

        return fields.reduce((accum, field, index) => {
            let dataField = this.pdfData.find(x => x['FieldName'] === field.fieldname), writeValue = field.fieldvalue;
            // if (dataField.hasOwnProperty('FieldStateOption')) {
            //     writeValue = field.fieldvalue ? dataField['FieldStateOption'] : 0;
            //}
            return [{ fieldname: dataField['FieldName'], fieldvalue: writeValue }, ...accum];
        }, []);
    }

That being said, _extractFieldNames(pdf) and _assignments(fields) don't appear to do the right thing. There can be multiple FieldStateOption lines, and this code only deals with the first one.

corymickelson commented 6 years ago

@dannymcpherson Thank you for bringing this to my attention. This library initial intent has been based on handling specific in-house pdf's and as such it hasn't had the greatest of exposure to other documents, if it's possible could you add the pdf file that is causing the issue so I may be able to reproduce and debug the issue. Thank you.

dannymcpherson commented 6 years ago

No problem at all, I'm very grateful you wrote this - it saved me a great deal of time!

http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf

pjm4 commented 5 years ago

Had the same problem. Issue is that you can't set it to 'Yes' as it ignores it and uses the value of FieldStateOption which is 'Off' in this case.

{ 
  FieldType: 'Button',
  FieldName: 'My Checkbox',
  FieldFlags: '0',
  FieldValue: 'Off',
  FieldJustification: 'Left',
  FieldStateOption: 'Off' 
}

Danny's work-around works a treat.

(Great library Cory - thanks for building it)