Using dynamic data to populate existing PDF

OK so trying to do some research into how I can populate an existing PDF form from a Government department and populate it with out customers information from a database.
Has anyone done this before or have any ideas on the best way to do it?

Have a look at https://tcpdf.org/ and/or http://www.fpdf.org/

@ben do you have a preference with these PDF creators? What are their strengths and weaknesses? I am going to have to integrate PDF creating and just started looking into what’s available.

FPDF preceded TCPDF and I think that you will find that, to understand the basics of the latter, you will need some knowledge of the former.

To answer your question, use TCPDF; but do not overlook FPDF.

2 Likes

I have used https://html2pdf.fr/en/home in several projects before, last time was probably about 5 years ago. It worked well but was quite simple. I will have a look at TCPDF, cheers.

Hi Ben, an old topic but was wondering if you have used TCPDF in Wappler with dynamic data?

How did you go about it and have you got any quick code you could copy and paste here to give me something to look at?

Cheers

Amazing free library that will export anything contained within the page to a .pdf file.

You can use CSS and provided classes to avoid page breaks and splits in the document.

1 Like

Hi Neil, I have come to the conclusion that the modern web browser does an excellent job at converting HTML to PDF.

Have a look at https://hollandtrade.com.au/wcart/, add a product or two, change the quantities and print or create a PDF.

All it takes is an inclusion of a button (or similar) like:
<button class="btn" onclick="javascript:window.print();"><i class="fas fa-print"></i>&nbsp; Print the Invoice</button>

1 Like

Morning Ben and thanks for coming back to me.

I agree that the modern web browser does an excellent job at converting HTML to PDF, but I need to do this in the background.

My requirement is that when a user has finished entering data into a form, they press a button which then creates a PDF report and emails to the predetermined recipients.

In a bit more detail…

  • User enters data into form
  • Presses ‘Save’ button to save data to DB
  • At the same time, a PDF is generated and saved to a reports directory
  • A link is shown to the PDF so the user can click on it to see and review the PDF Report
  • A ‘Send’ button is shown so the user can generate an email, attach the PDF Report, send the email - all in one go
  • User is returned to a dashboard where it confirms that the email has been sent.

In other words I want the system to generate the PDF on the fly and save it. All reports are court compliant and must be emailed as PDF.

Hi Dave, this seems to be a very expensive option (relative I know, but in my case an expensive option) or am I missing something?

You say free but I don’t see that.

Cheers

Totally free @UKRiggers ! The full UI kit is a commercial product but some of the libraries are freely available. This guide is probably the simplest to start with:

You will be up and running in ten minutes! Make sure to include the style sheet and the suggested fonts (they are very good for print).

We are producing 40 - 50 page PDF’s (in around 1.5 seconds full of data and stacked queries) with many images coming in at around 2.3mb - 2.8mb by including the compression recommendations. Quite impressive!

1 Like

Thanks @Dave, I will get onto this straight away. Much appreciate your guidance and it’s always good to get recommendation from somebody who is already benefiting from it.

1 Like

No worries. Have sent you a quick example video.

1 Like

If Dave’s solution works, great!

If it does not work for you, please come back here and I will give you my idea of how it can work without the insecurities of an email, all based on browser conversion and Wappler.

1 Like

Hi Ben, I am looking into Dave’s suggestion and it looks good for this particular issue.

Please share your idea with us as I am always looking for alternative ways of doing things. I have several projects on the go and some, much simpler than this, that may well benefit from a different approach.

I did not want to confuse the issue by coming with an alternative, but here goes.

  • user enters data into a form
  • the data is saved to to DB
  • an email is sent with a link to the document
  • the user is taken to the dynamically populated and secured document
  • A PDF of the document is securely downloaded using HTTPS

In case the user does not download the PDF in the above procedure, there are two ways that the document can be retrieved

  • using the email link
  • going to the archive in the website

To my severely saturated mind, I see no difference between clicking a PDF attachment to view the document and clicking a link to view the document. The big difference is the method of delivery, unsecured SMTP or secured HTTPS.

As a sidenote, I have some business in the Netherlands and this is the way that the Notaries over there send their legal documents, an email with a link and a download from the website.

1 Like

Hi Ben, always good to get another view on things. This makes a lot of sense: “The big difference is the method of delivery, unsecured SMTP or secured HTTPS”. I will put your suggestion to my client and see what he says.

Dave any chance of attaching your example video on this page?

I shall need to add a PDF feature at some point and would be interested in any information on the matter.

@pixlapps mentioned an API he was setting up to create PDFs externally. This looked like an interesting option too. It wasn’t free, but the costs seem to be pretty minimal.

@psweb Hi from the Middle Earth of Load shedding. I successfully used https://www.api2pdf.com

Using the url to pdf option. I you like send me a private message with your mail address and I will send you example files of my project.

Costs are nominal - You can add credit and it subtracks a couple of cents with each call.

Cost vs ease of use convinced me.

1 Like