Printing Grid Content

| Comments (34)

UPD: Download the most recent Grid-to-PDF packages for PHP, ASP.NET, and Java here.

If you’ve ever faced the problem of printing data from JavaScript tables, then this news will please you. At last we offer a solution for printing dhtmlxGrid content. Currently it works for PHP, but even if you develop in Java or Cold Fusion, or Ruby, or whatever, you still can use it from a PHP server through remote request.

How to print

The extension consists of two parts (dhtmlxgrid-to-pdf.zip):

  • A dhtmlxGrid extension JavaScript file (dhtmlxgrid_pdf.js),
  • A PHP background which creates a PDF file from grid content.

 
You can keep them both on the same computer as your application, or (which is really nice!) you can use a remote server for this. I.e., you can add the line of code below to your page with the grid and start creating PDFs right away:

<script src="http://www.dhtmlx.com/docs/products/devExchange/grid-to-pdf/dhtmlxgrid_pdf.js"></script>

 
To start creating PDF from your grid, use the following JavaScript command (assign it to the button or something):

grid.toPDF('http://www.dhtmlx.com/docs/products/devExchange/grid-to-pdf/generate.php');

 
Instead of using files from dhtmlx.com you can use their local copies, of course.

What you get

It is extremely easy to start using the extension, so you can try it right away with your application. Or you can see online sample here.

While creating PDF, you can choose a color scheme for it. There is a dropdown on the toolbar with three options: color, gray and black&white. Here is what you get in color:

color

Current version options are:

⋅ The color scheme can be chosen from: color, gray, black&white. To set it in the script method, use one of the following values as a second argument of the toPDF method: “color”, “gray”, “bw”.

⋅ You can use images as a header and footer for the PDF page. These images should be named header.[gif/jpg/png] and footer.[gif/jpg/png]. Put them in the imgs folder under grid-to-pdf.

To enable Header, set the third argument of the toPDF method to true. To enable Footer, set the forth argument of the toPDF method to true.

⋅ Orientation of the page will be automatically chosen based on column width.

dhtmlxScheduler-to-PDF is coming…

I must say that the same solution will be available for dhtmlxScheduler in a few days. I’ll describe it and show it in action in the next post.

Posted by Inga Kravtsova

Comments

  1. Richard Gustin January 14, 2010 at 3:01 am

    Hi,

    This does not work if there is HTML within one of the cells… ?

  2. ivan January 14, 2010 at 5:05 am

    Richard, it supports only simple html tags such as < i > and < b > , any other html markup will not be printed correctly.

  3. mahesh January 15, 2010 at 9:17 am

    When I try a simple version of:

    dhxGrid.toPDF(“generate.php”,”bw”);

    I get a blank new page without generation of a pdf file? Is there something I am missing? Thanks,
    -Mahesh

  4. mahesh January 15, 2010 at 9:19 am

    One other comment: I was trying to integate this into the table generation desribed earlier in this blog, and was unable to suceed. Is there an easy way to combine the two? Nice tools by the way.

  5. ivan January 18, 2010 at 9:38 am

    Manesh, everything works fine on our side. Please write to support (at) dhtmlx.com to get the help from our team.

  6. Richard Gustin January 18, 2010 at 7:40 pm

    Thanks,

    Does it work with images in the cells using the column “img”…. the reason im asking is because when i try and use this pdf generation utility it just spits errors out at me. Never actually generates anything…

  7. ivan January 19, 2010 at 2:37 am

    Richard,
    this version supports only text, inline images are not supported yet.
    If you have a sample where problem with printing can be reconstructed, please send it to support (at) dhtmlx.com .

  8. mahesh February 16, 2010 at 1:45 pm

    I am anxiously awaiting a version of scheduler to pdf printing. Any update on this process? Thanks,

  9. Yoshika March 18, 2010 at 10:38 pm

    How do I show footer row in the pdf that was obtained from attachFooter()? Or is there another way to display the footer row?

    Thanks

  10. Printing Capabilities. Part 2. dhtmlxSch... April 6, 2010 at 2:19 am

    […] three months ago, we introduced a solution for converting dhtmlxGrid in PDF to provide the ability to print grid content. Now comes the turn of dhtmlxScheduler, just as was […]

  11. Matcruz April 10, 2010 at 7:40 am

    Hi, how can i put a header and footer ??
    thak you

    • ivan April 15, 2010 at 5:22 am

      a) Save desired footer and header as:
      footer.png
      header.png
      b) Drop images in the /imgs folder of PHP service ( not in codebase! )
      c) use grid.toPDF(url, “color”, true, true )

      3rd and 4th parameters are controlling the header and the footer of pages.

  12. Ricardo April 19, 2010 at 10:28 am

    Hi. When I try to convert one grid to pdf, I receive “Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML'”. I tried it in test server and it work’s but when I move it to the production server, it starts to get this error. Thank’s

    • ivan April 26, 2010 at 10:11 am

      Be sure that you are using PHP 5.x and simpleXML module for php is enabled (normally it is enabled by default).

  13. Ricardo April 19, 2010 at 10:39 am

    Where is the class SimpleXMLElement? I can´t find it

  14. Ratheeshkumar July 5, 2010 at 2:57 pm

    PDF generation is not correct when some of the columns are disabled?

    • ivan July 6, 2010 at 1:52 pm

      For PDF it doesn’t matter if columns are disabled or not. If you’re encountering any problems with export to PDF, please post your question to our Forum – support staff will try to help you.

  15. Ratheeshkumar July 20, 2010 at 2:31 pm

    How can i set footer for the pdf? Not images; Is it possible to set images as footer and header only? I want to set date, page number and application name in the footer. Is it possible

    • Stanislav June 17, 2011 at 2:46 pm

      Without code modifications, you can use only images as header and footer of the final document.

  16. Sander Mertens March 18, 2011 at 12:41 pm

    Hello ,

    I have tried this solution and it works. However, when I use mutltiple headers in my grid, only the first header appears.
    Also, the footers that are attached to the grid don’t show up in the PDF. Am I doing something wrong?

    Thanks,

    Sander

  17. Victor June 4, 2011 at 12:52 pm

    I’m new to dhtmlx grid.
    U said “Instead of using files from dhtmlx.com you can use their local copies, of course.”.
    May i know how to do that?
    How to use that local copies in my jsp web application

    • Stanislav June 17, 2011 at 2:49 pm

      The package includes all necessary js and php files, so you can unzip it to some location inside the web server root and in the toPDF command use path to those local files instead of the one at dhtmlx.com

  18. Adriano December 22, 2011 at 12:22 pm

    Hi every body.
    i used exppdt and it work fine.
    but we purchase the version 3 of dhtmlxgrid codebase and the export did not work anymore.
    Need i an special version of the export ?

    • Stanislav December 22, 2011 at 12:38 pm

      There is no need for extra steps, just be sure that you have updated all js files to the latest version ( including dhtmlxgrid_export.js )

      If problem still occurs – try to update the server side export script from here:
      http://www.dhtmlx.com/docs/products/goodies/index.shtml

  19. Gaoyang June 20, 2012 at 7:05 pm

    Hi,this is not support for utf-8 strings, like chinese…

    • Ivan June 28, 2012 at 4:40 pm

      UTF-8 is supported. If you still experience this issue, please submit it to the forum:
      http://forum.dhtmlx.com/viewforum.php?f=23

      • heroying April 9, 2014 at 10:33 am

        how to export data use utf8??
        not found in document

        • Stanislav April 16, 2014 at 7:56 pm

          You need not do anything special. It must work by default.
          If you are using some rare charset, it possible that default font just has not glyph for it.

  20. Gaoyang June 20, 2012 at 7:06 pm

    if input utf-8 strings,system had error:Input is not proper UTF-8, indicate encoding

  21. sam March 5, 2013 at 4:28 pm

    hi sir
    i am try to export the grid but its not working?
    can you provide the proper any sample code which convert the pdf?

  22. Vadim May 8, 2013 at 5:02 pm

    Prompt please, prescribe a number of ways:
    gridReports.toPDF(baseUrl+’/grid-to-pdf/generate.php’);
    and the second:
    gridReports.toPDF(‘http://www.dhtmlx.com/docs/products/devExchange/grid-to-pdf/generate.php’);

    And they do not work. You receive a blank page with “eternal loading” and does not load. So, what I’m trying both locally and on the server. Why is it not working?

Leave a Reply