PDF Form filling with FPDF and then Flatten with PDFTK displays un-filled PDF

Blatant self promotion: Try my php-pdftk package. If you have pdftk installed, it's very easy to use.

composer require mikehaertl/php-pdftk

<?php
use mikehaertl/pdftk/Pdf;

$pdf = new Pdf('form.pdf');
// Fill in UTF-8 compliant form data!
$pdf->fillForm(array('name' => 'Any char: ÄÖÜ'))
    ->saveAs('filled.pdf');

// Alternatively: Send to browser for download...
$pdf->send('filled.pdf');

// ... or inline display
$pdf->send();

I was able to find another process to fill a PDF form and then flatten it. I still don't know why using the "Form Filling" script from fpdf.org did not work.

I followed the steps outlined here:

1) Get the field names if they are not already known

exec("pdftk templates/Test.pdf dump_data_fields >cache/testfields.txt");

2) Create a FDF file with the field names and field values and save it as Test.fdf

%FDF-1.2
1 0 obj<</FDF<< /Fields[
<</T(Name)/V(John Doe)>>
<</T(Address)/V(123 White Lane)>>
<</T(Age)/V(30)>>
<</T(Phone)/V(123-1234)>>
] >> >>
endobj
trailer
<</Root 1 0 R>>
%%EOF

3) Then fill the form and flatten it

exec("pdftk templates/Test.pdf fill_form templates/Test.fdf output cache/FilledFDF.pdf flatten");

Download resulting PDF (filled and flattened): FilledPDF.pdf