PDF - How to check a checkbox with FPDF?

Viewed 6115

I am using FPDF class to fill a form. I created on adobe acrobat (by retrieving the data from database). I have no problem for text boxes. but I don't know, how it works for check boxes (how to check them).

Here is my php code.

<?php 
$req = $bdd->query("my req");

if ($req && $req->rowCount() > 0) {
    $data = $req->fetch();
    require_once "fpdm.php";

    $fields = array(
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'mycheckbox' => $data['isAdult'] ? 'Yes' : 'Off'
    );

    $pdf = new FPDM("file.pdf");
    $pdf->Load($fields, true);
    $pdf->Merge();
    $pdf->Output("F", "fileToSave.pdf");
 }
 ?>

firstname and lastname fields are filled. but, mycheckbox isn't checked when it has to be checked.

1 Answers

This is not supported in fpdm. You could use this utility : 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');
Related