The latest Export packages for installation can be found here:
To export data from dhtmlxGrid into a pdf document:
For example, if you add a button by clicking on which dhtmlxGrid will start exporting, then your code can look like this:
// DHTMLX Suite is used <link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css"> <script src="codebase/dhtmlx.js"></script> <script src="codebase/dhtmlxgrid_export.js"></script> <input type="button" value="Get as PDF" onclick="mygrid.toPDF('codebase/grid-pdf-php/generate.php');"> <div id="gridbox" style="width:399px;height:270px;"></div> <script> mygrid = new dhtmlXGridObject('gridbox'); ... </script>
On the grid's page you need to include one more extension
<script src="codebase/dhtmlxgrid_export.js"></script>
To export grid's data to a PDF you need to add the button on the page, which will call the toPDF method. The parameter of toPDF method is the url of the script, which has been installed previously (./server/generate.php):
<input type="button" name="save" value="save" onclick="grid.toPDF('path/to/folder/generate.php')">
The only thing, which can be controlled on client side is color-map of image. You can choose between
grid.toPDF('path/to/folder/generate.php','gray');
generate.php contains a code, similar to the next
$pdf = new gridPdfGenerator(); $pdf->printGrid(&$xml);
You can apply some custom configuration options , before executing printGrid
Size of elements
//page offsets $pdf->minOffsetTop = 10; $pdf->minOffsetBottom = 10; $pdf->minOffsetLeft = 10; $pdf->minOffsetRight = 10; //element sizes $pdf->headerHeight = 7; $pdf->rowHeight = 5; $pdf->minColumnWidth = 13; $pdf->pageNumberHeight = 10; //font settings $pdf->fontSize = 8; //image settings $pdf->dpi = 96; $pdf->footerImgHeight = 50; $pdf->headerImgHeight = 50;
Color of elements ( “custom” colormap)
//main bg color of grid $pdf->bgColor = 'D1E5FE'; //color of border lines $pdf->lineColor = 'A4BED4'; //color of text in grid's header $pdf->headerTextColor = '000000'; //color of alter-css - even row $pdf->scaleOneColor = 'FFFFFF'; //color of alter-css - odd row $pdf->scaleTwoColor = 'E3EFFF'; //color of text in the data part $pdf->gridTextColor = '000000'; //color of the text on a page ( page number, etc. ) $pdf->pageTextColor = '000000';
Other setttings
//control processing of html tags $pdf->strip_tags = false;
It possible to define custom header and footer for each page.
grid.toPDF(url, "color", true, true);
As result you will have content of “header.png” and “footer.png” as header and footer on all pages in the generated pdf file.
If output of PDF file is failed, there must be file named as “error_report_xxxx.xml”, please send this file with any bug-reports.
If output doesn't fail, but still has some problems, you can edit generate.php and change
$debug = false;
as
$debug = true;
As result, there will be a new file saved, with name as “debug_xxxxx.xml” - please send it with related error report.