CS Lewis
CS Lewis

Reputation: 489

SelectPdf fails to properly generate pdf that needs to look like the rendered version of our ASPX page

Here is the information about my development environment:

-Microsoft Visual Studio Professional 2013

-.NET Framework 4.0

-jquery.min.js ( 1.11.3 )

-Select.HtmlToPdf (2.0.1.0)

-jQuery DataTables (1.10.7)

In our application, we have an ASPX page with dynamically populated jquery DataTables and a graph that is dynamically generated using jquery at runtime.

We were hoping to use Select.HtmlToPdf (2.0.1.0) to create pdf file that will look like the aforementioned ASPX page when it renders in a web browser.

In our ASPX page, we have a download pdf ASPX server-side button, that invokes the following C# method defined within the ASPX code behind file:

        public void generatePDF()
        {


            // instantiate a html to pdf converter object
            HtmlToPdf converter = new HtmlToPdf();

                        var url =
    HttpContext.Current.Server.MapPath("~/hos/pdf/displayTemplate.html");
        Console.WriteLine(url.ToString());

        SelectPdf.GlobalProperties.HtmlEngineFullPath =
HttpContext.Current.Server.MapPath("~/hos/pdf/SelectPdfAuxiliaries/Select.Html.dep");

        PdfDocument doc = converter.ConvertUrl(url.ToString());

        // save pdf document
        doc.Save(Response, false, "displayContent.pdf");

        }

The displayTemplate.html contains AJAX jquery functions that will invoke an ASHX handler:

    function GetHandlerTestJS() {
        var testHandlerData = new FormData();
        testHandlerData.append("handlerTestId", "1");
        $.ajax({
            type: "Post",
            contentType: "application/json; charset=utf-8",
            url: "testHandler.ashx",
            enctype: 'multipart/form-data',
            contentType: false,
            processData: false,
            data: testHandlerData,
            dataType: "json",

            success: function (data) {
                $('#handlertestDebug').html(data);
                //getSignatureImage();
            },
            error: function (Result) {
                $('#handlertestDebug').html("error in handler test"); $('#handlertestResultDebug').html(Result);
            }
            //beforeSend: function () { $('#loader').show() }, //complete: function () { $('#loader').hide(); }
        });
    }

    $(function () {
        $(document).ready(function () {
            console.log("Inside Start");
            GetHandlerTestJS();
        });
    });

The problem is that there is Failure to invoke the ASHX handler when using the Select.HtmlToPdf (2.0.1.0)'s API method called ConvertUrl :

   PdfDocument doc = converter.ConvertUrl(url.ToString());

Could someone please tell me what changes I need to make to the aforementioned code in such a way that it will invoke the handler from html using Select.HtmlToPdf (2.0.1.0)'s API ?

Upvotes: 0

Views: 1744

Answers (1)

WebDev3r
WebDev3r

Reputation: 76

Have you tried to use a full absolute path to testHandler.ashx?

Upvotes: 1

Related Questions