Click here to Skip to main content
16,012,173 members

Comments by Festar (Top 2 by date)

Festar 17-Sep-15 7:23am View    
Here is an article that demonstrates how to do that:
Convert HTML to PDF in C# and VB.NET[^]
I hope it helps.
Festar 16-Sep-15 8:24am View    
The problem is with a following:

Response.Write(strContents);

You see you're writing a DOCX file as if it were a plain text file and that will not work. You need to create a real DOCX file.
For that you can use quite a few options, for example you can try OpenXML SDK:
https://msdn.microsoft.com/en-us/library/dd440953(v=office.12).aspx
Or you can try a simpler approach with MadMilkman.Docx, like this:

// Create new DOCX file.
DocxFile document = new DocxFile();

// Add "strContents" as a HTML paragraph.
document.Body.AppendText("<body><p>" + strContents + "</p></body>", ContentType.Html);

MemoryStream stream = new MemoryStream();
// Save DOCX file to stream.
document.Save(stream);

// Write stream to Response...

Or you can try this word processing dll for C#, here is how you can create a word document in C# with it.