Click here to Skip to main content
15,846,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I had created a Microsoft 2007 docx output via OpenXML but now i want to change this output in PDF format.

Docx contain header,footer,various pages with graphical images as well as too much formatting.

So please suggest is there any possibility that I can convert the docx to pdf just by changing the Headers.

Using :Visual Studio 2010 Ultimate
3.5 framework
and for website project.

Below is the code which I tried to do the same:

//Creating new name and making .PDF
var resultname = Server.MapPath("App_data/doc/" + timeSpan + ".pdf");

//Here filename is a buffer or original word document.
       using (var mainDoc = WordprocessingDocument.Open(filename, false))
       using (var resultDoc = WordprocessingDocument.Create(resultname,WordprocessingDocumentType.Document))

           foreach (var part in mainDoc.Parts)
               resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId);


But it is giving me Unable to open file,Might corrupt.
Please suggest....

Thanks in Advance!!

Mahendra Varandani
Updated 3-Apr-12 4:56am
Duchatived 9-Sep-15 4:31am    
You mean just by changing the HTTP response's header? No, that won't work, you still have a document in DOCX format. What you need to do is convert a file in DOCX format into a PDF format with C#.
This is not an easy task to achieve, there is no build in solution for this in .NET, you'll have to use some third party .net library for word documents.

1 solution

Hi devpeter,

Thanks for suggestion..

But it a paid dll is there any unpaid/free solution in .net??

or what would be the best approach to do the If I have created my docx ready.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900