http://qs321.pair.com?node_id=11119986


in reply to Filling PDF Form Checkboxes

follwing code works for me though there is an error message "Unknown resource key 'Encoding' in form field dictionary at /usr/local/share/perl/5.26.1/CAM/PDF.pm line 2914."
#!/usr/bin/perl -w use strict; use CAM::PDF; my $pdf = CAM::PDF->new('tenant.pdf') or die "Could not open PD +F ($!)!"; my @fields = $pdf->getFormFieldList(); foreach my $field ( @fields ) { if ($field =~ /Female/) { my $ff_obj = $pdf->getFormField($field); $ff_obj->{value}->{value}->{AS}->{value} = "On"; } else { $pdf->fillFormFields($field => $field); } } $pdf->cleanoutput('afilled.pdf');

Replies are listed 'Best First'.
Re^2: Filling PDF Form Checkboxes
by Anonymous Monk on Aug 03, 2020 at 18:20 UTC

    Upon further research on the checkbox issue, I just realized that {AS}->{value} is where you can control the option

    In the same PDF file that I worked in above instance, there is another kind of check box in the dictionary that is using indirectObject

    which points to a parent dictionary which has {AS}->{value}. In this instance {AS}->{value} was set "Off" initially but I had to use {D}->{value} which is inside of the same parent dictionary to set {AS}->{value} to turn check box on,in my case, it is "Yes_2", that is {AS}-{value}="Yes_2"

Re^2: Filling PDF Form Checkboxes
by Anonymous Monk on Jul 29, 2020 at 15:12 UTC

    I have used following improved code to mark my checkbox in pdf

    #!/usr/bin/perl -w  use strict; use CAM::PDF;  my $pdf = CAM::PDF->new('tenant.pdf') or die "Could not open PDF ($!)!";  $pdf->getFormFieldList();  my $field ="Female";  my $ff_obj    = $pdf->getFormField($field);        $ff_obj->{value}->{value}->{AS}->{value} = "On";   $pdf->cleanoutput('afilled.pdf');