0

I have an asp.net ASHX handler which is accepting xml data as input and generating a pdf document and returns it to the response as follows:

 public override void NowProcessTheRequest(XmlWriter xw)
    {
       var bytes = get pdf bytes from service based on input xml xw

       var fileName="test";
       context.Response.ContentType = "application/pdf";
       context.Response.Headers.Add("Content-Disposition",
       string.Format("inline; filename=report_{0}_{1}.pdf", fileName, DateTime.Now.ToString("MM_dd_yyyy")));
       context.Response.Write(bytes);
       context.Response.Flush();
  }

now i want to open the generated pdf in a new window from javascript.

i am not able to use "window.open" as i am not sure how to pass xml in the body. so what option i have to call this ashx handler from javascript and post a xml data and open the response pdf in a new window.?

Alagesan Palani
  • 1,984
  • 4
  • 28
  • 53
  • why not sessions?? Create Your DataTable of XML and Put it in the Session – Dgan Feb 10 '15 at 13:55
  • if i put xml in session, i have to clean up the session after the request processing, as this xml input is needed only for the current request.i am looking for some option to pass the xml in body so the xml lives only for the request – Alagesan Palani Feb 10 '15 at 13:59
  • `"Content-Disposition"` header indicate to browser download of resource ? – guest271314 Feb 10 '15 at 14:25
  • See http://stackoverflow.com/questions/9852190/js-window-open-then-print – guest271314 Feb 10 '15 at 15:47
  • @guest271314 key point that is missing is how to post xml data to the ashx handler that generate response for the new window we are opening. any idea about that? – Alagesan Palani Feb 11 '15 at 01:51

1 Answers1

0

echo xml input ?

var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><abc>123</abc>";

$.post("/echo/xml/", {xml:xml}, "xml")
.then(function(xml) {
    var res = $(xml).find(":root")
    , popup = window.open("", "popup", "width=600,height=400");
    popup.document.body.innerHTML = res.get(0).outerHTML;
    popup.focus();
    popup.print();   
});

jsfiddle http://jsfiddle.net/guest271314/trsvLmhm/

See js window.open then print()

Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177