Issue while exporting to PDF

Hello Team,

i am new to dxhtml.

i do have a requiremnet to export the grid data in PDF format.
I do not want to use MVC patten in my project.

i do have code following thing.

    <input type="button" name="" value="Generate PDF" style="width: 300px; font-weight: bold;"
    [b] onclick="mygrid.toPDF('/PDF);"><[/b]br><br>
    var mygrid;
    function doInitGrid() {
        mygrid = new dhtmlXGridObject('mygrid_container');

my .ashx file code.
public void ProcessRequest(HttpContext context)

        var writer = new PDFWriter();

        context.Response.ContentType = writer.ContentType;
        context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
        context.Response.AppendHeader("Content-  Disposition", "attachment;filename=grid.pdf");
        context.Response.AppendHeader("Cache-Control", "max-age=0");

        var xml = context.Request.Form["grid_xml"];

        xml = context.Server.UrlDecode(xml);

        var stream = writer.Generate(xml);



i do have below issue.
I am not able to use the myGrid.toPDF function properly.
I am getting the below error.
Microsoft JScript runtime error: Object doesn’t support property or method ‘toPDF’

I am using the latest version and using the .net version 4.0
so do need a help to genarete the PDF using .net.
Please suggest your views on same.

Hello Ajay,
.toPDF is defined in grid export extension(ext/dhtmlxgrid_export.js), have you attached it?

Yes, I do have attached that export.js.
I also want to understand this.toPDF take one paratmeter that is the URL.

What is this Url ? we have to specify. I don’t understand this url concept.

please help on same.


The url is the path to where your pdf generation class is, i.e. class PDFGenerator if you are using version. This class will return the grid’s data in a pdf format which will be shown in the browser or you can have the user save them.

Hope this helps.


Is this Url is same for IHTTPHander path.?

Yes, it is a path to httpHandler, e.g. mygrid.toPDF("<%= this.ResolveUrl("~/Generate.ashx") %>"); .toPDF method serializes grid structure and content to XML and sends it to the specified handler, which should generate and return PDF

Thanks a lot.

It helps.