ARTICLE

Convert Microsoft Office Word to other formats (pdf, html, rtf, xps)

Posted by Suthish Nair Articles | Office Development August 24, 2010
This article shows how to convert a Microsoft Word document to other document formats such PDFs, HTML, Rich Text Format (RTF), Text, XML, xps.
Reader Level:
Download Files:
 

This code snippet shows how to convert a Microsoft Office Word document to other document formats such 

PDFs, HTML, Rich Text Format (RTF), Text, XML, xps. We are going to use Office Interoperability for this purpose. 

Download the Primary Interop Assemblies (PIAs) from following links.

MS Office 2007

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=59daebaa-bed4-4282-a28c-b864d8bfa513&displaylang=en

MS Office 2010

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=938fe8ad-583b-4bd7-a345-23250dc15855

Adding the references.

  • Right click on your project.
  • Select Add Reference.
  • Go to .Net tab.
  • Select Microsoft.Office.Interop.Word from list.
    Samples attached using MS Office 2010 PIAs.
    1.jpg
    Sample codes attached. If you have any questions, post them below.

Login to add your contents and source code to this article
Article Extensions
Contents added by Dharmendra Singh on Mar 14, 2013
hi
 this project work only local host when it is uploaded on server it gives


Could not load file or assembly 'Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies

how to solve
Contents added by Suthish Nair on Mar 02, 2011
yes, referring from bin folder only. You need to add the dlls to bin folder. 
Contents added by Sunita Tajanpure on Dec 28, 2010
Does this reference to Microsoft.Office.Interop.Word or Excel refer to the GAC assembly or to the bin folder?

I want a code that should refer to the sin folder dlls not from the local system assemblies
Can anyone tell how to do this?


post comment
     

I m using same functionality in windows store app but its giving me below error (Creating an instance of the COM component with CLSID {000209FF-0000-0000-C000-000000000046} using CoCreateInstanceFromApp failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). Please make sure your COM object is in the allowed list of CoCreateInstanceFromApp.)

Posted by Mithila Mestry Apr 12, 2013

now days everyone going for openxml. No installation required.

Posted by Suthish Nair Mar 07, 2013

will it work without installing MS WORD in server?

Posted by Sreenivas Eemani Mar 03, 2013

Try Saaspose Word Converter (http://saaspose.com/api/words) it can convert your word documents to many other formats and also allows you to create document from scratch.

Posted by zarfishan zahid Nov 01, 2012

without ms word installing it will not work.

Posted by vikram Jul 03, 2012
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter