I'm trying to fill out a PDF form through FPDM, like in this example: http://www.fpdf.org/en/script/script93.php
Filling out text, date, decimal, ... inputs works correctly, but I can't find out how to check checkboxes and grouped checkboxes (radio buttons). This are two problems:
true
or or "true"
or "1"
or 1
or "checked"
or "on"
or "yes"
doesn't activate the checkboxes (case-sensitively tested too). Which value do I have to set to activate checkboxes?"FPDF-Merge Error: field yourtype not found"
. What is the correct name? Adobe Acrobat Pro DC shows the name "yourtype" as the name for all checkboxes in the group. In the field-list it shows the grouped checkboxes as "yourtype#0", "yourtype#1", "yourtype#2", etc. But the script doesn't seem to be able to find any of this names. I also tried something like "yourtype[1]" without luck. And as soon as I can access them, do I have to set the value for one of them, or do I assign the (integer?) value just directly?My example:
<?php
require('fpdm.php');
$fields = array(
'forname' => 'Jon Dow', // text input: works
'mycheck1' => true, // checkbox: doesn't work! Also tried "true", 1, "1", "yes", "on", ... (with case-sensitive)
'yourtype' => true, // grouped checkbox (radio button): doesn't even find input with that name.
);
$pdf = new FPDM('template.pdf');
$pdf->Load($fields, true);
$pdf->Merge();
$pdf->Output();
?>
Edit: The FPDM class does not seem to support setting some types like checkboxes and dropdowns. In the file fpdm.php
says the following in the header unter the ToDo section: extends filling to another form fields types (checkboxes,combos..)
As you mentioned it's not supported in fpdm. I was looking for another library that allow doing this and I found this : php-pdftk
Code sample :
// Fill form with data array
$pdf = new Pdf('doc.pdf');
$pdf->fillForm([
'CheckBox1' =>'Yes',
'RadioButton'=>'Choice1',
'name'=>'Wizard'
])
->needAppearances()
->saveAs('doc_filled.pdf');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With