Free Support Forum - aspose.com

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 the issue appears to be out of the scope of Aspose.Pdf and relates more to web-technologies(AJAX) itself, but we have deeply analyzed the problem. Using of HttpResponse appeared in API before AJAX , without AJAX in mind and writes to response some headers and content itself.

The idea of AJAX is in essence exchange with server without the reload of whole page. In such case request/response go throw additional layers on server and client (JS) and often are wrapped into some additional HTML/XML code. Direct usage of Response object in such cases can easily violate that wrapping, because inside Save(…) method some additional content/headers are written into Response object. That’s why usage of saving to Response in that context(AJAX) leads to problems.

We are not entirely certain if its a desirable behavior of the handler of button, but for illustrative purposes and to ensure that there is no problems in Aspose.Pdf itself, we have made little bit changes to code against Button1_click handler in order to avoid saving into Response inside Aspose.Pdf:

[C#]

protected void Button1_Click(object sender, EventArgs e)<o:p></o:p>

{

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);

pdf.Save(Server.MapPath("out.pdf"));

// it's simplistic way to ensure that file created and closed -

// it used in 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 created PDF-document on server in application's folder and redirects browser to that file to show it in same browser window (according to your requirements as per our understanding). We can see that it works fine : after click on button [Button], created PDF file is shown in same browser window.


Exact implementation of AJAX approach in such case is out of scope of Aspose.Pdf - and requires understanding and experience of working with AJAX itself.

You may take content from that result file, add some headers to it(If some additional things needed) and send to browser (to implement AJAX-packing of content).

To review issue :

  1. Please find attached corrected project,unzip it, put Aspose.Pdf dll of checked version into Bin folder, open project in VS2010 and run debugging. You'll see browser window with something shown on start screenshot (Screen_start.png).
  2. Then click on Button1. After 3-4 seconds you'll see PDF document with text "Hello World" in 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.