Check documentation for the latest version of dhtmlxSuite Exporting Data to PDF,Excel DHTMLX Docs

Exporting Data to PDF,Excel

Pay attention to the fact that dhtmlxGrid doesn't provide full support for data export in the smart rendering or paging modes and exports just the data which is already rendered on the client (not all the data).

PDF

The latest Export packages for installation can be found here:

To export data from dhtmlxGrid into a pdf document:

1) Download and unpack the appropriate Export package to the root level of your web server to the folder codebase (you don't need to install anything, just unpack).

2) Call the method toPDF(path). The method takes as a parameter the path to the generate.php file resided in the Export package.

For example, if you add a button by clicking on which dhtmlxGrid will start exporting, your code can be similar to this one:

// DHTMLX Suite is used
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css">
<script src="codebase/dhtmlx.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>

Coloring the resulting document

The toPDF() method takes the second (optional) parameter that can be used to control the color map of the resulting PDF document.

  • 'color' - full-color printing (used by default);
  • 'gray' - prints in shades of black and white;
  • 'bw' - prints in black and white only, no color options available;
  • 'custom' - prints in the custom defined colors ( colors are defined in the gridPdfGenerator.php file ).

Custom header and footer images

The toPDF() method takes the third and the fourth (optional) parameters that can be used to set custom header (footer) images for the grid.

To add a header image to the grid:

  • create an image with the name "header.png";
  • put the image to the grid-pdf-php folder;
  • set the 3rd parameter of the toPDF() method to true.
mygrid.toPDF('codebase/grid-pdf-php/generate.php','color',true);

To add a footer image to the grid:

  • create an image with the name "footer.png";
  • put the image to the grid-pdf-php folder;
  • set the 4th parameter of the toPDF() method to true.
mygrid.toPDF('codebase/grid-pdf-php/generate.php','color',false,true);

Excel

The latest packages for installation can be found here:

To export data from dhtmxlGrid into an Excel document:

1) Download and unpack the appropriate Export package to the root level of your web server to the folder codebase (you don't need to install anything, just unpack).

2) Call the method toExcel(path). The method takes as a parameter the path to the generate.php file resided in the Export package.

For example, if you add a button by clicking on which dhtmlxGrid will start exporting, your code can be similar to this one:

// DHTMLX Suite is used
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css">
<script src="codebase/dhtmlx.js"></script>
 
<input type="button" value="Get as Excel" 
onclick="mygrid.toExcel('codebase/grid-excel-php/generate.php');">
<div id="gridbox" style="width:399px;height:270px;"></div>
 
<script>
    mygrid = new dhtmlXGridObject('gridbox');
    ...
</script>

Configuration

You can define what dhtmlxGrid will look like in a PDF or Excel document after it is exported, configuring the available options in the server-side code:

  • in case of exporting to PDF - the gridPdfGenerator.php file;
  • in case of exporting to Excel - the gridExcelGenerator.php file.

Errors handling and logging

If any error occurs during data exporting and the result output is failed, a log file named as 'error_report_xxxx.xml' is automatically created in the grid-pdf-php (grid-excel-php) folder .

If output isn't failed, but still there are some problems, you can edit the generate.php and change the value of the debug variable to provoke generating of another log file named as 'debug_xxxxx.xml' :

$debug = false;
//change to
$debug = true;

Online export services

In order not to download the Export package you may use online export services and call the toPDF() and toExcel() methods as:

// exporting to PDF by using the online export service
mygrid.toPDF("https://export.dhtmlx.com/grid5/pdf/");
 
// exporting to Excel by using the online export service
mygrid.toExcel("https://export.dhtmlx.com/grid5/excel/");
Back to top