.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Word To Pdf Converter in ASP.Net

Posted By:Sasi Prabhu       Posted Date: June 04, 2011    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

Convert .doc, .docx, .txt, .rtf Document into PDF Document

Word To PDF Converter in ASP.Net :

Convert .doc, .docx, .txt, .rtf Document into PDF Document


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



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 Template
                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 Property
            ref UnknownType,    			// Original Font Embedding
            ref UnknownType,    			// Save Picture
    	    ref UnknownType,				// Saving Form Data
            ref UnknownType,    			// Save as AOVE Letter
            ref UnknownType,    			// Encoding
            ref UnknownType,    			// Inserting Line Breaks
            ref UnknownType,    			// Allow Substitution
            ref UnknownType,    			// Line Ending
            ref UnknownType);   			// Add BiDi Marks    

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);

 Subscribe to Articles


Further Readings:

Author: Tommy         Company URL: http://www.dotnetspark.com
Posted Date: March 27, 2014

My work involves dealing with PDF and Word docs a lot, and it is required to save important files in PDF formats instead of Word, so I''m using Yiigo to convert Word to PDF.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend