Click here to Skip to main content
15,868,054 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am faced with a problem. I want to take some html, pass it to some library and convert it to a pdf. I'm reading the html from the frontend, using jquery, and I want to pass it to a HttpHandler which converts it and downloads it.The issue is that the html string is too long and I end up with a small portion of that html.
I've tried to pass the html using ajax, querystrings and even cookies, nothing works, do you have any other method of passing a long string of html?

What I have tried:

The way I pass the data in javascript:

var html = $("#gg").html();

     var dataToSend = JSON.stringify({'wiki': html});

     jQuery.ajax({
        contentType: "application/json; charset=utf-8",
        url: "FileDownloader.ashx",
        dataType: "json",
        data: dataToSend,
        success: function(msg)
        {
           alert(msg.d);
        },
        error: function(type)
        {
            alert("ERROR!!" + type.responseText);
        }
     });


The way I read it in the HttpHandler:
public void ProcessRequest(HttpContext context)
        {
            var html = "";

            var value = context.Request["wiki"];
            html = HttpUtility.UrlDecode(value, System.Text.Encoding.Default);
            IronPdf.PdfDocument pdf = htmlToPdf.RenderHtmlAsPdf(html);
            byte[] PdfBinary = pdf.BinaryData;
            }
Posted
Comments
F-ES Sitecore 20-Apr-18 8:47am    
Try using "POST" as the ajax type

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900