We have a web application that serves medical data to hospitals. Our application uses Aspose.Words to open a Word 2003 Document (*.doc), perform a mail-merge of the data into the document, then displays the document as a PDF in the Browser:
This worked fine in development, but when we published, we got complaints that people were getting blank windows instead seeing the PDF embedded in the browser. I was able to replicate this locally by uninstalling Reader 8.x and installing Reader 6.x. (We also have reports of clients with IE6/Reader6 who upgraded to Reader 8 but still have the issue).
I tried several things, such as using Response.End(), saving the PDF locally and setting the contentType to application/pdf, streaming it out myself, etc. Nothing seems to help.
If I save the PDF to the hard drive and open it locally in Reader, it opens just fine.
Our next attempt will be to create an *ashx handler and see if that helps, but I’m running out of options. Has anyone else had this problem? Any resolution?
Thanks for your request. The Save(“out.pdf”, SaveFormat.Pdf, SaveType.OpenInBrowser, Response) method works like the following code.
Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
builder.Write("Hello world!!!");
MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Pdf);
Response.Clear();
// Specify the document type.
Response.ContentType = "application/pdf";
// Other options:
// Response.ContentType = "text/plain"
// Response.ContentType = "text/html"
// Specify how the document is sent to the browser.
// Response.AddHeader("content-disposition","attachment; filename=MyDocument.doc");
// Another option could be:
Response.AddHeader("content-disposition", "inline; filename=out.pdf");
// Get data bytes from the stream and send it to the response.
byte[] bytes = stream.GetBuffer();
Response.BinaryWrite(bytes);
Response.End();
You can try using this code for testing, if the problem still exists, then the problem is not related to Aspose.Words but to your environment configuration.
Best regards.
A small addition to the code above.
Writing the whole stream buffer directly to the output stream might actually result in a corrupt file, use to following instead: