使用 php laravel 填写 Pdf 表单

Fill Pdf form using php laravel

我正在尝试填写 pdf 并使用 php 保存它。我也试过 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 配置 pdftk

后我的代码是 bleow
 $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);

此结果始终 return 错误且错误消息为空。 如果我做错了什么或者有没有更好的解决方案来填写 PDF 表单,谁能帮我解决这个问题?

谢谢。

->flatten() 更改为 needAppearances()

注意:填写UTF-8数据时,应始终添加needAppearances()选项。这将确保 PDF reader 负责使用正确的字体进行渲染,这是 pdftk 无法为您做的。另请注意,如果您的数据中有特殊字符,flatten() 并不能很好地工作。

https://github.com/mikehaertl/php-pdftk