//Here is the way to generate html into canvas into PDF
1 add can js files
jquery.js
JS/html2canvas.js
JS/jquery.plugin.html2canvas.js
2.get the html content to convert into canvas
$('.hideDivs').hide();
$('.formdrop').hide();
$('.block').html2canvas({
onrendered: function (canvas) {
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/jpg"));
$('#img_val3').val($('.block').html()); //html of div
//Submit the form manualy
}
});
3. PHP back end with TC PDF
if(isset($_REQUEST['img_val'])):
//Get the base-64 string from data
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//Save the image
$imgfile=FCPATH.'images/submsnimage_'.$this->session->userdata('admin_id').'.jpg';
$imagegerated=file_put_contents($imgfile, $unencodedData);
chmod($imgfile, 0777);
$pdfImageFile=site_url()."images/submsnimage_".$this->session->userdata('admin_id').'.jpg';
endif;
4 PDF generation
ini_set('max_execution_time',300);
require_once (FCPATH.'tcpdf/config/lang/eng.php');
require_once (FCPATH.'tcpdf/tcpdf.php');
$exa = new TCPDF ();
$exa->SetCreator ( PDF_CREATOR );
$exa->SetAuthor ( 'Clay County Admin' );
$exa->SetTitle ( 'Clay County Form' );
$exa->SetSubject ( 'Example of TCPDF' );
$exa->SetKeywords ( 'TCPDF, PDF, PHP' );
$exa->SetFont ( 'times', '', 18 );
$exa->AddPage ();
$exa->Image ($pdfImageFile, 15, 10, 430,630);
$exa->AddPage ();
$exa->Image ($pdfImageFile2, 15, 10, 430,630);
$exa->AddPage ();
$exa->Image ($pdfImageFile3, 15, 10, 430,630);
$exa->setImageScale(PDF_IMAGE_SCALE_RATIO);
$exa->setJPEGQuality (100);
$root=site_url();
$exa->setImageScale(1.53);
$txt ="";
$exa->WriteHTML ($txt, true, false, true, false, '');
$exa->Output (FCPATH.'uploads/pdf/clayCommunityBullyReport.pdf', 'F' ); // downloads the pdf