How To generate a PDF after submitting a webform

I have created a webform and I want to do 2 actions when the user click on the SUBMIT button.
1 - send an email
2 - generate a PDF file.

How can I do this, please ?

Thanks in advance for your help.

Joel.

Hi Joel,

In order to send emails from a webform, go to your webform->Settings-> Emails/Handlers->Add email

Then fill out the values in the settings of the email handler. You can also use tokens for the fields. For example if one of the fields is the email address of the user, you can use it so the user receives an email automatically after the submission of the form.

Regarding the PDF file generation. Do you want to generate a PDF file for every submission so you can access it or you want to generate a PDF file with the values of the submission and attach it to an email and send it?

I want that each submission generate the PDF with all the info provided by the FORM which has been filled by the user and attached this PDF to the mail send.

Hi Joel,

That needs some work but I have done it already for another website and if you follow the steps below it should work.

First you need to install three modules modules:

  • PDF generator
  • Mail System
  • Swiftmailer

Drupal’s default mail system can’t send attachments. The only way that can is Swiftmailer and in order to change the mail system after you install Swiftmailer is with the Mail System module.

PDF generator and Swiftmailer require external libraries. The first needs dompdf again and works with ludwig but the second needs the swiftmailer library that needs to be installed in a way similar to the Entity print.

After you have installed and enabled all these modules and set the Swiftmailer in the mail system as the default one for webforms, you need to follow this guide https://www.youtube.com/watch?v=Zj1HQNGTHFI&feature=youtu.be&t=213

It shows you how to create a webform and to generate PDFs and attach them and send them to the submitters.

If you want I can’t copy all these modules to your website and enable them in order to save you time and then you will have only to create the webform following the Youtube video.

If you agree let me know to which website should I install them.

HI, I appreciate your help and the web site is again ep-th-safety.web.cern.ch :smile:

Done!

I created a backup first just in case called “before swiftmailer”.

I have installed and setup all the modules you need in order to do this.

Just watch the Youtube video and create your webform with the PDF attachment.

Let me know if you need more help.

I am coming back to you as it seems that the “downlaod PDF” does not work anymore.
I get “The website encountered an unexpected error. Please try again later.”

ANy idea what could be the issue ?
Could it be link to the latest update of drupal ?
Thanks in advance.
Joel.

the error is:
2020-01-16T17:53:10.355394+01:00 drupal8p22 httpd: [proxy_fcgi:error] [pid 1872906] [ep-th-safety.web.cern.ch] [client 128.141.212.193] AH01071: Got error 'PHP message: TypeError: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, boolean given in /drupal/sites/ep-th-safety.web.cern.ch/modules/entity_print/lib/dompdf-dompdf/v0.8.3/lib/html5lib/TreeBuilder.php on line 3257 #0 /drupal/sites/ep-th-safety.web.cern.ch/modules/entity_print/lib/dompdf-dompdf/v0.8.3/lib/html5lib/TreeBuilder.php(3257): DOMNode->appendChild(false)\n#1 /drupal/sites/ep-th-safety.web.cern.ch/modules/entity_print/lib/dompdf-dompdf/v0.8.3/lib/html5lib/TreeBuilder.php(3208): HTML5_TreeBuilder->appendToRealParent(false)\n#2 /drupal/sites/ep-th-safety.web.cern.ch/modules/entity_print/lib/dompdf-dompdf/v0.8.3/lib/html5lib/TreeBuilder.php(1495): HTML5_TreeBuilder->insertElement(Array)\n#3 /drupal/sites/ep-th-safety.web.cern.ch/modules/entity_print/lib/dompdf-dompdf/v0.8.3/lib/html5lib/Tokenizer.php(2458): HTML5_TreeBuilder->emitToken(Array)\n#4 /drupal/sites/ep-th-safe

It seems that it doesn’t work only for the latest submission. The old ones are fine. Maybe some of the values cause dompdf to crash.

Try to submit one with less values like the old ones to see if it still works.

For the record, here some additional configuration concerning webform and PDF generation, How to customize PDF generated by a Webform submission?

I want to send a pdf file to each email after the form submit. I don’t want to generate a pdf, I want to send the pdf file I already have. Can anyone please help with this? I am using the webform module to create forms. I have three fields on the form, Firstname, Lastname, and Email. I want to send an email with an attached pdf to each email entered on the form submit.

Dear User

Check Webform Entity Print module

best regards
Guillermo