Free Support Forum -

PDF generated as HTML

I am attempting to create a PDF from a word based template. When I render the PDF I get a file that contains HTML. I'd love some insight as to what I am doing incorrectly. The following code is used:

switch (format)


case "doc":


HttpContext.Current.Response, "BookingForm.doc", ContentDisposition.Attachment, SaveOptions.CreateSaveOptions(SaveFormat.Doc));



case "docx":


HttpContext.Current.Response, "BookingForm.docx", ContentDisposition.Attachment, SaveOptions.CreateSaveOptions(SaveFormat.Docx));

HttpContext.Current.Response.End(); // Required for docx




HttpContext.Current.Response, "Booking.Form.pdf", ContentDisposition.Attachment, SaveOptions.CreateSaveOptions(SaveFormat.Pdf));




// doc.Save(docOutput, saveFmt, SaveType.OpenInApplication, HttpContext.Current.Response);

return "";

Note: I get the correct out put for the .Doc but the .Pdf and .Docx render with html.

Hi Keith,

Thanks for your inquiry.

I'm afraid I can't reproduce any issues on my side using your code. Could you please create a sample application which allows me to reproduce the issue on my side?


attached is the .cs Module where I am recieving the error.


Thank you for additional information. But I also unable to reproduce the problem. Have you tried to remove Response.End() line? Does this make any difference?

Also, please try calling Response.Clear() before saving the document. Maybe this helps.

Best regards,

I originally did not include the Response.End lines for Default (.Pdf) and .Docx type files. I removed these statements and added a Response.Clear() prior the doc.Save call. Same format issue.

There is something peculiar perhaps about my installation. I am receiving this error, and an "Object reference not set to an instance of an object" error posted in another thread. I just upgraded my assemblies from 8.0.0 to 10.1.0. Perhaps I installed or am building incorrectly? As I said before, I can display a .Doc file just fine, not the .Pdf or .Docx.

Thank you for additional information. Saving to response works as the following code.

MemoryStream stream = new MemoryStream();

doc.Save(stream, SaveFormat.Pdf);


//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.pdf");

//Another option could be:

//Response.AddHeader("content-disposition", "inline; filename=out.doc");

//Get data bytes from the stream and send it to the response.

byte[] bytes = stream.GetBuffer();



Just for testing purposes, try using this code and let me know if it works.

Best regards,

I attempted to execute this code, but was not sucessful. It appears to be a security related issue. There is another active thread that is addressing this topic. Once we make some progress on that issue, I’ll readdress and retest this area.


Thank you for additional information. Please let us know if you need some help from our side. We will be glad to assist you.

Best regards,