mikehaertl\pdftk\Pdf::fillForm PHP Method

fillForm() public method

Fill a PDF form
public fillForm ( string | array $data, $encoding = 'UTF-8', $dropXfa = true, $format = 'xfdf' ) : Pdf
$data string | array either a XFDF/FDF filename or an array with form field data (name => value)
return Pdf the pdf instance for method chaining
    public function fillForm($data, $encoding = 'UTF-8', $dropXfa = true, $format = 'xfdf')
    {
        $this->constrainSingleFile();
        if (is_array($data)) {
            $className = '\\mikehaertl\\pdftk\\' . ($format === 'xfdf' ? 'XfdfFile' : 'FdfFile');
            $data = new $className($data, null, null, null, $encoding);
        }
        $this->getCommand()->setOperation('fill_form')->setOperationArgument($data, true);
        if ($dropXfa) {
            $this->dropXfa();
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testCanFillFormFromFile()
 {
     $form = $this->getForm();
     $fdf = $this->getFdf();
     $file = $this->getOutFile();
     $pdf = new Pdf($form);
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->fillForm($fdf));
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->needAppearances());
     $this->assertTrue($pdf->saveAs($file));
     $this->assertFileExists($file);
     $tmpFile = (string) $pdf->getTmpFile();
     $this->assertRegExp("#pdftk A='{$form}' fill_form '{$fdf}' output '{$tmpFile}' drop_xfa need_appearances#", (string) $pdf->getCommand());
 }
All Usage Examples Of mikehaertl\pdftk\Pdf::fillForm