Hi,
Thanks for your patience.
We have further investigated the issue reported earlier and it does not seem to be a bug in our API. Even though the issue appears to be out of the scope of Aspose.Pdf and relates more to web technologies (AJAX) itself, we have deeply analyzed the problem. The usage of HttpResponse appeared in the API before AJAX, without AJAX in mind, and writes to the response some headers and content itself.
The idea of AJAX is, in essence, exchanging with the server without reloading the whole page. In such cases, the request/response goes through additional layers on the server and client (JS) and is often wrapped into some additional HTML/XML code. Direct usage of the Response object in such cases can easily violate that wrapping because inside the Save(..) method some additional content/headers are written into the Response object. That’s why using saving to Response in that context (AJAX) leads to problems.
We are not entirely certain if it’s a desirable behavior of the handler of the button, but for illustrative purposes and to ensure that there is no problem in Aspose.Pdf itself, we have made some changes to the code against the Button1_click handler in order to avoid saving into Response inside Aspose.Pdf:
[Code] C#
protected void Button1_Click(object sender, EventArgs e){
string html = "<html><body>Hello World</body></html>";
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
pdf.IsTruetypeFontMapCached = false;
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, html);
text2.IsHtmlTagSupported = true;
section.Paragraphs.Add(text2);
//pdf.Save("Report1.pdf", Aspose.Pdf.Generator.SaveType.OpenInAcrobat, Response);
pdf.Save(Server.MapPath("out.pdf"));
// it's a simplistic way to ensure that the file is created and closed.
// it is used for illustrative purposes and
// on production, it should be replaced with more robust code
System.Threading.Thread.Sleep(3000);
Response.Redirect("out.pdf");
//Response.End();
}
Fixed sample just saves the created PDF document on the server in the application’s folder and redirects the browser to that file to show it in the same browser window (according to your requirements as per our understanding). We can see that it works fine: after clicking on the button [Button], the created PDF file is shown in the same browser window.
Exact implementation of the AJAX approach in such a case is out of the scope of Aspose.Pdf and requires understanding and experience of working with AJAX itself.
You may take the content from that result file, add some headers to it (if some additional things are needed), and send it to the browser (to implement AJAX packing of content).
To review the issue:
Please find attached the corrected project, unzip it, put the Aspose.Pdf dll of the checked version into the Bin folder, open the project in VS2010, and run debugging. You’ll see a browser window with something shown on the start screenshot (Screen_start.png).
Then click on Button1. After 3-4 seconds, you’ll see the PDF document with the text “Hello World” in the same browser’s window (please see screen_pdf_after+click.png).
Please try using the latest release of Aspose.Pdf for .NET 9.8.0 and in case of any further query, please feel free to contact.