ARTICLE

Word To PDF Converter

Posted by Prabhu M Articles | Office Development June 03, 2011
This article explains a way to convert a Microsoft Word Document to PDF Format.
Reader Level:
Download Files:
 

Introduction

word2pdf1.jpg

word2pdf2.jpg

This article explains a way to convert a Microsoft Word Document to PDF Format. The operation is very simple. This is used to Convert the .doc, .docx, .txt, .rtf  Document into .pdf Document.

Steps

Choose Website -> Add Reference -> .Net -> Microsoft.Office.Interop.Word 12.0.0.0 and Click on Ok.

word2pdf3.jpg
 
Code

Namespace

using Microsoft.Office.Interop.Word;

private Microsoft.Office.Interop.Word.ApplicationClass MSWordDoc;
object UnknownType = Type.Missing;

To Open the Word Document

MSWordDoc.Documents.Open(ref InputLocation,    //Input File Name Location
    ref UnknownType,    // Conversion Conformation
    ref UnknownType,    // Set ReadOnly Property
    ref UnknownType,    // Add to the Recent Files
    ref UnknownType,    // Document Password Setting
    ref UnknownType,    // Password Templete
    ref UnknownType,    // Revert
    ref UnknownType,    // Write Password to Document
    ref UnknownType,    // Write Password Template
    ref UnknownType,    // File Format
    ref UnknownType,    // Encoding File
    ref UnknownType,    // Visibility
    ref UnknownType,    // To Open or Repair
    ref UnknownType,    // Document Direction
    ref UnknownType,    // Encoding Dialog
    ref UnknownType);   // XML Text Transform
                
To Get Document in PDF Format 

object SavePDFFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;


To SaveAs the Document 

MSWordDoc.ActiveDocument.SaveAs(ref OutputLocation, //Output File Location
ref SavePDFFormat,    // File Format
ref UnknownType,    // Comment to PDF File
ref UnknownType,    // Password
ref UnknownType,    // Add to Recent File
ref UnknownType,    // Write Password
ref UnknownType,    // ReadOnly Propert
ref UnknownType,    // Original Font Embeding
ref UnknownType,    // Save Picture
ref UnknownType,    // Saving Form Datas
ref UnknownType,    // Save as AOVE Letter
ref UnknownType,    // Encoding
ref UnknownType,    // Inserting Line Breakes
ref UnknownType,    // Allow Substitution
ref UnknownType,    // Line Ending
ref UnknownType);   // Add BiDi Marks
result = "Success";

To Close the Document File

MSWordDoc.Documents.Close(ref UnknownType, ref UnknownType, ref UnknownType)

To Exit the Word Application

MSWordDoc.Quit(ref UnknownType, ref UnknownType, ref UnknownType);

Login to add your contents and source code to this article
post comment
     

hi, its not working in my system its getting error please send the file to banakarharish@gmail.com

Posted by harish naik b Jul 07, 2012
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
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.
Get Career Advice from Experts