简体   繁体   中英

Generate fillable / editable PDF in Laravel

I am generating DOM PDF in laravel using barryvdh/laravel-dompdf package. It is working fine by rendering the views and HTML elements with readonly mode. But, I am trying to generate fillable / editable PDF so that user can enter details with out opening it in 3rd party editor tools.

Below is the code snippet I am using to generate PDF with barryvdh/laravel-dompdf package.

    $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.

    $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 supports rendering form fields as static content in the PDF but not for rendering fillable forms.

Using niklasravnsborg/laravel-pdf that uses mpdf , you can use active forms to archive a fillable PDF.

There's an extense mpdf active forms example .

So, the blade html should look like:

<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 .

You could also use FPDF . I think it's the best open-source PDF generator there is. You can easy import it, and you can select one dozen different pdf templates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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