Docx to PDF - Unable to open in browser

Hello there.

I am trying to output a docx document to a PDF and offer it to the client in the browser. However this does not work. It says: "The file is damaged and could not be repaired."
I can save the document to a directory on my harddrive and then open it without any problems though.
I have attached a very simple docx for you to test with, one which creates the error for me.

Here is my converting code (mostly copied from the programmer's guide on how to convert a document to PDF):

// Save the document in the Aspose.Pdf.Xml format.
String xml = dir + "/saves/brieftopdf.xml";
doc.Save(xml, SaveFormat.AsposePdf);
// Read the document into Aspose.Pdf.
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(xml, null);
// Instruct to delete temporary image files.
pdf.IsImagesInXmlDeleteNeeded = true;
// This is optional, but can speed up Aspose.Pdf if you convert multiple files in one session.
// pdf.IsTruetypeFontMapCached = false;
// pdf.TruetypeFontMapPath = Path.GetTempPath();
// Produce the PDF file.

Then either of the following 3:
1. pdf.Save(dir + "/saves/brief.pdf"); <---WORKS
2. pdf.Save("brief.pdf", Aspose.Pdf.SaveType.OpenInBrowser, Response); <--- DOESN'T WORK
3. pdf.Save("brief.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response); <--- DOESN'T WORK

I hope you can help me out. Thanks in advance.

Greetings,

Jip

Hold on, adding Response.End() to the end of the code seems to fix the problem :slight_smile: