Create Dynamic PDF file for download after form submission

Hi,

I am trying to create a downloadable dynamic PDF that’s contains data from a form that is submitted. The form is linked to a server action that creates a database record in a table. It’s PHP server model.

I have tried HTML to PDF without any success. I am not a PHP programmer and just wondering if any one could assist on how to achieve this. Just need to include the dynamic database from the inserted record and can create the layout using HTML.

Any guidance would be appreciated.

Here you go.. :slight_smile:
https://community.wappler.io/search?q=php%20pdf

The easiest one i could find that worked for me...
I generated the php or html file.. then let the api generate the pdf...

and another good one by @Dave

I use PDFmonkey. It’s $10 per month and very powerful. Also very easy to design with so you can create very professional, pixel perfect documents very easily.

2 Likes

I’ll take a look. Haven’t come across it. Thanks for sharing!

I would suggest using tfpdf. It’s a simple php library that can be used with Wappler very easily. If you like I can even share you some example files that work directly with Wappler. Let me know if you are interested!

1 Like

Hi @jellederijke yes that would be very much appreciated if you can share some files. I need to have a look at all my options. Thanks again for this.

You can download FPDF here. The way I use it is I create a folder in the home directory of my Wappler project called something like custom_modules. Then place the fpdf folder inside that. So each time you want to use fpdf you need to point to that folder from a server action, through the api module.

You can see inside the fpdf folder some examples of how these php files work. I am no php dev either, but it was simple enough for me to understand after some time.

So the next question is, how do you send data to this php file, in order to have your own data in the pdf that is created.

So the way I do this is add some code near the top of the php file, AFTER the <?php line. This code declares some variables where you can send data to (in this case folder_name, file_name and name_client):

// Get variables from form post
$folder_name= isset($_POST['folder_name']) ? $_POST['folder_name'] : "";
$file_name= isset($_POST['file_name']) ? $_POST['file_name'] : "";
$name_client= isset($_POST['name_client']) ? $_POST['name_client'] : "";

you can then use these variables to print it as text in a cell:

$pdf->Cell(130,5,$name_client,0,0);

or use to declare where you want to save the pdf file, like so:

$pdf->Output('../..'.$folder_name.'/'.$file_name.'.pdf', 'F');

In a server action you can create the pdf and send data like so:

And point towards the right php file, you edited in the tfpdf folder:

If you run this server action (you can just test it in your browser) it will create a pdf, just like that!

I hope this makes sense to you. If not, let me know where you get stuck.

1 Like

Thanks very much @jellederijke. I will have a look and give it a try and let you know how I go.

We’ve integrated a client-side App Connect PDF Creator component in Wappler 6.3.0
Please check it and let us know what do you think: Using App Connect PDF Creator

Note that more options will be coming to it in the next updates!

1 Like

This topic was automatically closed after 32 hours. New replies are no longer allowed.