Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wkinne's avatar

PDF Templates

Hi!

Has anyone dealt with creating pdf templates on the server and then filling them in with data?

For example if there is a form that a user fills out. When they submit I would like to grab a PDF that is already on the server, edit the fields with the submitted form data, generate a new pdf and save back to the server.

Very similar to using a third party like Hello SIgn, but brining that in house so I don't have to use a service.

Thank You!

0 likes
8 replies
jlrdw's avatar

Some old school thought

  • User fills out a form
  • That data is saved to a database table
  • Ready to put that stored data in pdf
  • just put it there like any field would be done
christiangerdes's avatar

I've used the package that @topvillas mentioned like so:

$view = view('pdf-view', ['data' => $data])->render();

$pdf = resolve('dompdf.wrapper');
$pdf->loadHTML($view);

return $pdf->stream('PDF');

I don't think it's a good idea to store the PDF in the database. Just store the fields and then serve the pdf using the stored data.

wkinne's avatar

Thanks for all replies!

So it looks like I have to convert existing pdfs into HTML.

There must be a way to map fields on a PDF because services like right signature and hello sign do it. But maybe just not able in php.

christiangerdes's avatar

You can map fields on a PDF. Just create a normal view with blade variables and implement the code above...

wkinne's avatar

Sorry not being very clean on my end.

What if I already have a PDF. Every time someone fills out some information. That PDF is used and then the data that is entered gets put in that existing pdf as a new pdf.

christiangerdes's avatar

That's alright!

I don't think you can accomplish the PDF generating without a HTML representation of the PDF. You have to create a HTML template for the PDF and then generate the filled PDF. I think that's the only way.

jlrdw's avatar

So it looks like I have to convert existing pdfs into HTML.

Or just start new with having the person fill out a form store that data and when you are ready to generate the PDF generate with the stored data from database. I don't know if that would work for you or not but just an idea.

Please or to participate in this conversation.