- Posts: 77
- Thank you received: 6
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript"> var contenu=$("#canvas").html(); var filename = "{INFO1}-{SAVEDID}"; $.ajax({ url:"/upload/templates/bpf-cosmed/views/html2pdf.php", type:"post", data: { data: contenu, filename: filename }, complete: function (xhr,result){ var msg=xhr.responseText; } }); </script>
mattheoh wrote: Just to let you know , I managed to generate automatically a PDF of the assessment, whicj is compiled when the assessment page is displayed. I used the library HTML2PDF.
Also added a button to send, the PDF by mail.
The name of the PDF is : INFOX-IDSURVEY.PDF which permits to add it an equation question to display it in the board.
if someone needs the script I can post it here.
Thanks again for the help.
mrli999 wrote: Could you please post it here? Thanks.
<script type="text/javascript" charset="utf-8"> $(window).load(function(){ $(document).ready(function() { var content = $("#canvas").html(); var fichier = "{INFO1}-{SAVEDID}"; var societe = "{INFO1}"; var codepostal = "{INFO2}"; var ville = "{INFO3}"; var personne = "{INFO4}"; var fonction = "{INFO5}"; var personnemail = "{INFO6}"; var expert = "{TOKEN:FIRSTNAME} {TOKEN:LASTNAME}"; var expertmail = "{TOKEN:EMAIL}"; $.ajax({ url: "/upload/html2pdf/pdf_engine.php", method: "post", data: { filename: fichier, data: content, company: societe, cp: codepostal, town: ville, person: personne, job: fonction, persmail: personnemail, exp: expert, expmail: expertmail }, }); }); }); </script>
<?php /** * HTML2PDF Library - example * * HTML => PDF convertor * distributed under the LGPL License * * @package Html2pdf * @author Laurent MINGUET <webmaster@html2pdf.fr> * @copyright 2016 Laurent MINGUET * * isset($_GET['vuehtml']) is not mandatory * it allow to display the result in the HTML format */ require_once(dirname(__FILE__).'/html2pdf.class.php'); // get the HTML ob_start(); // get the filename and data from POST $filename = $_POST["filename"]; $data = $_POST["data"]; $societe = $_POST["company"]; $codepostal = $_POST["cp"]; $ville = $_POST["town"]; $personne = $_POST["person"]; $fonction = $_POST["job"]; $personnemail = $_POST["persmail"]; $expert = $_POST["exp"]; $expertmail = $_POST["expmail"]; include(dirname(__FILE__).'/modele-rapport-pdf.php'); $content = ob_get_clean(); try { // init HTML2PDF $html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', array(0, 0, 0, 0)); // display the full page //$html2pdf->pdf->SetDisplayMode('fullpage'); // convert $html2pdf->writeHTML($content, isset($_GET['vuehtml'])); // add the automatic index //$html2pdf->createIndex('Sommaire', 30, 12, false, true, 2); // send the document to the browser and force the download $path = "/var/www/mydomaine/website/upload/pdf/"; $filename = $filename . ".pdf"; $html2pdf->Output($path . $filename, "F"); // return the filename to ajax request echo $filename; } catch(HTML2PDF_exception $e) { echo $e; exit; }
<style type="text/css"> <!-- table.page_header {width: 100%; border: none; background-color: #c7d4d9; border-bottom: solid 2px #2c3e50; padding: 1mm; font-size: 9pt;font-family: Helvetica} table.page_footer {width: 100%; border: none; background-color: #c7d4d9; border-top: solid 2px #2c3e50; padding: 1mm;font-size: 7pt; font-family: Helvetica} div.content {text-align: left; font-size: 11px; font-family: Helvetica; padding: 3mm; width: 95%;} ul { width: 95%; list-style-type: square; } ul li { padding-bottom: 1mm; } h1 { text-align: left; font-size: 15px} h3 { text-align: left; font-size: 13px} --> </style> <page backtop="3mm" backbottom="3mm" backleft="3mm" backright="3mm"> <table class="page_header"> <tr> <td style="width: 50%; text-align: left"> <p style="font-size: 12pt; font-weight: bold;">Rapport</p> <ul> <li>Date : <b><?php echo date('d-m-Y'); ?></b></li> <li>Soci&eacute;t&eacute; : <b><?php echo $societe; ?></b></li> <li>Code Postal : <b><?php echo $codepostal; ?></b></li> <li>Ville : <b><?php echo $ville; ?></b></li> <li>Personne interrog&eacute;e : <b><?php echo $personne; ?></b></li> <li>Fonction : <b><?php echo $fonction; ?></b></li> <li>Email : <b><?php echo $personnemail; ?></b></li> <li>Expert BPF Cosmed : <b><?php echo $expert; ?></b></li> <li>Email expert : <b><?php echo $expertmail; ?></b></li> </ul> </td> <td style="width: 50%; text-align: right"> <img src="./logo-cosmed.png" alt="Logo HTML2PDF" style="width: 200px"> </td> </tr> </table> <div class="content"> <?php echo $data; ?> </div> <page_footer> <table class="page_footer"> <tr> <td style="width: 50%; text-align: left;"> Rapport<b><?php echo $societe; ?></b> </td> <td style="width: 50%; text-align: right"> R&eacute;alis&eacute; par <b><?php echo $expert; ?></b> le <?php echo date('d-m-Y'); ?> </td> </tr> </table> </page_footer> </page>
<div style="text-align: right"> <a href="/upload/pdf/{INFO1}-{SAVEDID}.pdf" download="{INFO1}-{SAVEDID}.pdf" class="btn btn-default">Télécharger le rapport</a> <div id="sendmail" class="btn btn-default">Envoyer fichier PDF</div> <div id="success" style="display: none; color: #18bc9c;"> Fichier bien envoyé !</div> </div> <script type="text/javascript" charset="utf-8"> $(function() { $("#sendmail").click(function() { var email = "{TOKEN:EMAIL}"; var societe = "{INFO1}"; var fichier = "{INFO1}-{SAVEDID}.pdf"; $('#success').show().delay(5000).fadeOut(); $.ajax({ type: "POST", url: "/upload/html2pdf/sendmail.php", data: { to: email, filename: fichier, company: societe }, }); return false; }); }); </script>
<?php $societe = $_POST['company']; $email_to = $_POST['to']; // The email you are sending to (example) $email_from = "your@email.com"; // The email you are sending from (example) $email_subject = "Rapport - $societe"; // The Subject of the email $email_txt = "Vous trouverez ci-joint le rapport pour la soci&eacute;t&eacute; $societe"; // Message that the email has in it $fileatt_name = $_POST['filename']; // Filename that will be used for the file as the attachment $fileatt = "/var/www/yourdomain/website/upload/pdf/$fileatt_name"; // Path to the file (example) $fileatt_type = "application/pdf"; // File Type $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers="From: $email_from"; // Who the email is from (example) $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_txt; $email_message .= "\n\n"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; $mailsent = mail($email_to,$email_subject,$email_message,$headers); ?>