Html to convert pdf save in to folder and Mail

Here Example of html table structure to convert to pdf using jspdf.

<table id= “xyz”><thead><tr><th>id</th></tr></thead>

You can add style tag inline and give css to it.

Thereafter Include require Js file

var doc = new jsPDF(‘l’, ‘pt’, ‘a4’);
var specialElementHandlers = {
‘#xyz’: function(element, renderer){
return true;
var table = document.getElementById(“xyz”);
var res = doc.autoTableHtmlToJson(table, true);
doc.autoTable(res.columns,, {
startY: 60,
tableWidth: ‘auto’,
columnWidth: ‘auto’,
styles: {
overflow: ‘linebreak’
beforePageContent: function(data) {
doc.text(“New Pdf”, 40, 30);}
var pdf =doc.output(); //returns raw body of resulting PDF returned as a string as per the plugin documentation.
var data = new FormData();
data.append(“data” , pdf);
var xhr = new XMLHttpRequest(); ‘post’, ‘test.php’, true ); //Post to php Script to save to server

After That Create new php file to post data on it and using phpmailer you can attached and mail. eg:test.php

require_once “../../PHPMailer/class.phpmailer.php”; // Download phpmailer
$data = $_POST[‘data’];
$fname = ‘newpdf-‘.date(‘d-m-Y’).’.pdf’; // name the file
$file = fopen(“../pdf/” .$fname, ‘w’); // open the file path
fwrite($file, $data); //save data
$bodytext = ‘Please Find PDF’;
$email = new PHPMailer();
$email->From = ‘’;
$email->FromName = ‘My first pdf’;
$email->Subject = $file;
$email->Body = $bodytext;
$email->AddAddress( ‘’ );
//$email->AddAddress(‘’, ‘Person Two’);
//$file_to_attach = $_SERVER[‘DOCUMENT_ROOT’].’/front/pdf’;
$email->AddAttachment(‘../pdf/’.$fname );

return $email->Send();
} else {
echo “No Data Sent”;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s