-1

Background Drupal 8 have a great new feature: Ability to use entity_print to export submissions as pdf, and even to attach the pdf to email and send.

Request Because of the sensitivity of some information, sending them by email is not an acceptable option. Is it possible, to instead automatically generate the PDF when a submission is created or updated, and save it in a directory on the server or another external location?

Thanks for any help...

  • Welcome to Drupal Answers! Sorry you got downvoted. But unfortunately your question is way too broad. Please update your question to include your previous attempts; to share a detailed and narrowly-scoped problem and where exactly you are stuck right now. Many thanks :) – leymannx Jun 30 '19 at 14:49
0

There is a drush command that will export all PDF documents in the tar file.

drush webform-export --exporter='webform_entity_print:pdf' contact >  contact.tar.gz

Otherwise, you would have to write custom code to generate the PDF documents when a submission is created. You can use WebformEntityPrintWebformExporter::writeSubmission as starting point for generating a submission's PDF document.

BTW, I do not recommend generating the PDF when a submission is created because it would slow down your site. Instead, I would queue the PDF generating.

  • Hi; Thanks for your advice on this request. After analysis, the solution that will work for my case will be to generate a pdf file after each form submission. I've followed your tutorial on webform entity print and ended up with a pdf field that is attached to my form. From that I can get the pdf version of the form without problem. Then I've created a handler I will like to use to auto export the pdf. This is where I'm stocked. – sibopa Jul 23 '19 at 4:18
  • I'm using the public postSave function, and trying to use $webform_submission->getData() to get the value of the the ['pdf'] array, and use system_retrieve_file() to get the file and save it to my location. 2 issues: the get->Data() is not getting the pdf value; and when I trick the system and use and existing pdf, the files is copied to the location, but is corrupted. I think WebformEntityPrintWebformExporter::writeSubmission as you sugested will work, but don't know how to use this... – sibopa Jul 23 '19 at 4:24
  • PDF generation has access controls to protect user data and if you try to call the generated PDF via system_retrieve_file() you will get an access denied page. You need to extract the code which writes the PDF from WebformEntityPrintWebformExporter::writeSubmission. – jrockowitz Jul 23 '19 at 10:57
  • Yes, thanks. I know that's the way to go. Can you please help me with and example of achieving this? my current standing. I've already setup webform and webformentityprint, and attached a pdf field to generate the pdf. I'm using the postSave function in my handler. Can you show me how in my postSave function I can use WebformEntityPrintWebformExporter::writeSubmission and save the generate form somewhere? Thanks! – sibopa Jul 23 '19 at 13:15
  • I think you can use this snippet as starting point, drupal.org/project/entity_print/issues/2843869#comment-11920433 – jrockowitz Jul 23 '19 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.