gtroop Report post Posted July 7, 2017 i would like to use fusionchart with tcpdf...the chart is loading correctly in my php page but not in pdf generated by tcpdf How do i include the fusionscript script correctly in the pdf? can anyone help with an example <?php include(MY_ROOT_PATH."/header.php"); include "Charts/FusionCharts2.php"; require_once MY_ROOT_PATH . '/class/libraries/vendor/tcpdf/tcpdf.php'; // Creating the item object for the selected item <script type="text/javascript" src="Charts/fusioncharts.js"></script> <script type="text/javascript" src="Charts/themes/fusioncharts.theme.fint.js"></script> <script type="text/javascript"> FusionCharts.ready(function(){ var revenueChart = new FusionCharts({ "type": "column2d", "renderAt": "chartContainer", "width": "500", "height": "300", "dataFormat": "json", "dataSource": { "chart": { "caption": "Monthly revenue for last year", "subCaption": "Harry's SuperMart", "xAxisName": "Month", "yAxisName": "Revenues (In USD)", "theme": "fint" }, "data": [ { "label": "Jan", "value": "420000" }, { "label": "Feb", "value": "810000" }, { "label": "Mar", "value": "720000" }, { "label": "Apr", "value": "550000" }, { "label": "May", "value": "910000" }, { "label": "Jun", "value": "510000" }, { "label": "Jul", "value": "680000" }, { "label": "Aug", "value": "620000" }, { "label": "Sep", "value": "610000" }, { "label": "Oct", "value": "490000" }, { "label": "Nov", "value": "900000" }, { "label": "Dec", "value": "730000" } ] } }); revenueChart.render(); }) </script> // Extend the TCPDF class to create custom Header and Footer class MYPDF extends TCPDF { //Page header public function Header() { } // Page footer public function Footer() { // Position at 15 mm from bottom $this->SetY(-15); // Set font $this->SetFont('helvetica', 'I', 8); // Page number $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); } } // create new PDF document $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins //$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetMargins(PDF_MARGIN_LEFT, 0, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->setPrintHeader(false); // remove default footer $pdf->setPrintFooter(true); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); } // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); //The first parameter is meant to be an array of strings with identifiers as content that indicates which permissions should be removed from the PDF. //print : disable the possibility to print the PDF from any PDF viewer. //modify : prevent the modification of contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble'; //copy : prevent the copy or otherwise extract text and graphics from the document; //annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields); //fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified; //extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes); //assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set; //print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality. //owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions. $pdf->SetProtection(array('modify','copy','annot-forms','fill-forms','extract','assemble')); // add a page $pdf->AddPage(); $pdf->SetAuthor('Gtroop'); $pdf->SetTitle('Testing FusionCharts'); $html .= '<div id="chart-container">FusionCharts will render here</div><br />'; // set javascript $pdf->IncludeJS($js); // writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') // writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true) $pdf->writeHTML($html, true, false, true, false, ''); // --------------------------------------------------------- // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document ob_end_clean(); $pdf->Output('test.pdf', 'I'); exit(); //============================================================+ // END OF FILE //============================================================+ Share this post Link to post Share on other sites
gtroop Report post Posted July 7, 2017 Okay i guess i need to save the chart as a graphic and then include that graphic in tcPDF i tried it something like this nothis happened $webpageURLWithChart = "chart1.php"; $outputImageFileName = "images/charts/savedImage.jpg"; $delay = 500; $shellout = shell_exec("C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe --javascript-delay $delay $webpageURLWithChart $outputImageFileName" ); echo $shellout; Share this post Link to post Share on other sites
Prerana Report post Posted July 10, 2017 Hello, Thanks for the query. Kindly elaborate the requirement, so that we can assist you further. Share this post Link to post Share on other sites