Pdf Save does not open in new window

When I use the following:

doc.Save(Response, "Name", ContentDisposition.Attachment, SaveOptions.CreateSaveOptions(SaveFormat.Pdf));

I get the Open/Save dialog. If I choose Open, it replaces my currently open browser window with the PDF file with no way to return to my previous browser session.
I have gotten around this problem by not using the built in functionality of Aspose with System.Web like this:

MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Pdf);
Response.AddHeader("Content-Type", "binary/octet-stream");
Response.AppendHeader("Content-disposition", "attachment; filename= fileName.Pdf");
byte[] bytes = stream.GetBuffer();
Page.Response.Flush();
Page.Response.BinaryWrite(bytes);
Page.Response.Flush();
Page.Response.End();

This works, but I am curious, is there a setting I am missing in order to use the the first method?

This message was posted using Aspose.Live 2 Forum

Hello

Thank you for request. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.

I can see two differences:

  1. In the first Document.Save you use “Name” whereas in your second manual method you use “Name.pdf” e.g. with the .pdf extension. Make that makes the difference?
  2. Aspose.Words uses the “application/pdf” content type, whereas you use “binary/octet-stream”. I think “application/pdf” is the correct one to use and I don’t think it affects the browser.

Try that and let us know if that helped.

I tested both suggestions.
Changing application/pdf and binary/octet-stream made no difference.
Adding the “.pdf” at the end of the file name did make a difference.
thanks

Hello

It is perfect, that you already resolved the problem. Please let us know in case of any issues. We will be glad to help you.
Best regards,