简体   繁体   English

在Laravel中生成可填写/可编辑的PDF

[英]Generate fillable / editable PDF in Laravel

I am generating DOM PDF in laravel using barryvdh/laravel-dompdf package. 我使用barryvdh / laravel-dompdf包在laravel中生成DOM PDF It is working fine by rendering the views and HTML elements with readonly mode. 通过使用只读模式呈现视图和HTML元素,它工作正常。 But, I am trying to generate fillable / editable PDF so that user can enter details with out opening it in 3rd party editor tools. 但是,我正在尝试生成可填写/可编辑的PDF,以便用户可以输入详细信息,而无需在第三方编辑器工具中打开它。

Below is the code snippet I am using to generate PDF with barryvdh/laravel-dompdf package. 下面是我用来生成带有barryvdh / laravel-dompdf包的PDF的代码片段。

    $file = "Storage/pdf/document.pdf";
    $data = array("foo" => "bar");
    $view = view('pdf.document', $data);
    \PDF::loadHTML($view)->setPaper('A4', 'portrait')->setWarnings(false)-save($file);

I have also tried mpdf niklasravnsborg/laravel-pdf package but this is also opening in readable mode. 我也尝试了mpdf niklasravnsborg / laravel-pdf包,但这也是在可读模式下打开。

    $data = [
        'foo' => 'bar'
    ];
    $pdf = PDF::loadView('pdf.document', $data);
    return $pdf->stream('document.pdf');

Please suggest me if I need to configure any options to this code. 如果我需要为此代码配置任何选项,请建议我。

Create a PDF with a fillable form with dompdf its not possible, because it's not supported , owner says: 创建可填写表单与DOMPDF不可能 PDF文件,因为它不支持的 ,老板说:

Dompdf supports rendering form fields as static content in the PDF but not for rendering fillable forms. Dompdf支持将表单字段呈现为PDF中的静态内容,但支持呈现可填写表单。

Using niklasravnsborg/laravel-pdf that uses mpdf , you can use active forms to archive a fillable PDF. 利用使用MPDF niklasravnsborg / laravel-PDF,您可以使用活性形式存档可填写PDF。

There's an extense mpdf active forms example . 有一个extend mpdf活动表单示例

So, the blade html should look like: 所以,刀片html应该是这样的:

<h2>Active Forms</h2>
<form action="formsubmit.php" method="post">
  <b>Input Text</b>
  <input type="text" size="90" name="inputfield" value="" title="The title attribute works like a tool-tip" />
</form>

Another possible solution would be use laravel-fpdf package, that uses FPDF . 另一种可能的解决方案是使用laravel-fpdf包,它使用FPDF

You could also use FPDF . 您也可以使用FPDF I think it's the best open-source PDF generator there is. 我认为它是最好的开源PDF生成器。 You can easy import it, and you can select one dozen different pdf templates. 您可以轻松导入它,并且您可以选择一打不同的pdf模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM