6

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.

Divakar Gujjala
  • 803
  • 8
  • 24

2 Answers2

7

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.

Troyer
  • 6,765
  • 3
  • 34
  • 62
0

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 Bumpaster
  • 944
  • 7
  • 20
  • Hard does not mean it's not possible... I know that dompdf is newer but it's more dedicated for crafting pdf with html elements... – The Bumpaster Mar 26 '18 at 08:12