I'm trying to fill a pdf and save it using php. I'm also tried FPDF
this script but its throws a error FPDF-Merge Error: Object streams are not supported
. After I'm also tried php-pdftk
package. I'm using ubuntu 20.04 so there no instruction to found install pdftk server for Ubuntu on there website. I'm install it using method 3 of this web site given Pdftk ubuntu install bleow is my code after configure pdftk
$pdf = new Pdf(public_path().'/test.pdf');
$result = $pdf->fillForm([
'name_field'=>'hello',
])
->flatten()
->saveAs(public_path().'/filled.pdf');
// Always check for errors
$error ='';
if ($result === false) {
$error = $pdf->getError();
}
return response()->json($error, 200);
this result always return false and error message is empty. Can any one help me to figure this out if I'm done anything wrong or Is there any better solution for fill PDF form?
Thank you.
Change ->flatten()
to needAppearances()
.
Note: When filling in UTF-8 data, you should always add the needAppearances() option. This will make sure, that the PDF reader takes care of using the right fonts for rendering, something that pdftk can't do for you. Also note that flatten() doesn't really work well if you have special characters in your data.