Click here to Skip to main content
15,124,972 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 C#.net for website project.

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

C#
//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!!

Regards
Mahendra Varandani
Posted
Updated 3-Apr-12 4:56am
v2
Comments
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 same...as If I have created my docx ready.
   

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