Save method using SaveType.OpenInAcrobat not working

I have the requirement to convert a html string to a pdf document from
a asp.net page.

I'm using IE 9, Aspose.Pdf_8.5.0v, VS 2010.

The following block of code does not force the Response to open the
Aspose pdf document in Adobe Acrobat. The pdf document is being
downloading to the IE client, but, w/ only the option to 'Save'.
When I save the download, there is no pdf extension and no
'Hello World' text inside the document.
What am I doing wrong?

string html = "Hello World";

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);
Response.End();

Hi there,


Thanks for your inquiry. We’ve tested the scenario with Aspose.Pdf for .NET 8.5.0 and we are unable to reproduce the issue. Its working as expected, shows dialogue with open, save and cancel option. Can you please share a sample project to replicate the issue? So we will test the scenario at our end and will provide you more information.

Best Regards,

I 'cleaned' my VS project and put the Aspose Pdf Save code
(shown above) inside a button click event handler located
inside the same aspx page that was being displayed, and now IE gives
the prompt to 'Open', 'Save' the resulting downloaded converted
Pdf file. So, that solves my original question in this thread.

I was hoping I could use an IHTTPHandler or a separate
aspx page, because I wanted to convert the html file
asynchronously, either using jQuery or a Server.Transfer call.

Obviously, this Aspose.Generator.Pdf behavior is by design.
My next question is, why would Aspose.Pdf Save method
cause a a file to be sent to the client w/o the pdf extension
when called through jQuery / ajax / in an asp.net
IHTTPHandler?

Hi there,

Thanks for your feedback.

jsholsinger:

I 'cleaned' my VS project and put the Aspose Pdf Save code
(shown above) inside a button click event handler located
inside the same aspx page that was being displayed, and now IE gives
the prompt to 'Open', 'Save' the resulting downloaded converted
Pdf file. So, that solves my original question in this thread.

Its good to know that you have managed to get your desired results.

jsholsinger:

I was hoping I could use an IHTTPHandler or a separate
aspx page, because I wanted to convert the html file
asynchronously, either using jQuery or a Server.Transfer call.

Obviously, this Aspose.Generator.Pdf behavior is by design.
My next question is, why would Aspose.Pdf Save method
cause a a file to be sent to the client w/o the pdf extension
when called through jQuery / ajax / in an asp.net
IHTTPHandler?


In reference to PDF file generation without extension , Can you please share a sample application here? So we will investigate it and provide you more information accordingly.

Moreover, Please check this forum thread to open PDF document in a new browser window.

Best Regards,

Hi there,


We’ve further investigated the issue and able to replicate the issue at our end. We’ve logged the issue as PDFNEWNET-35911 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue progress via this forum thread.

We are sorry for the inconvenience caused.

Best Regards,

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.