There are many tools available to covert your word document to PDF and multiple ways availbale  to do that but i got the eaisier way , would like to share here..
Prerequisite is that you need office 2007 or letter version in your system.
Download Save-as-PDF addon for your office version from here and installed It.
Now when you save any word document then Save as (.PDF) option will be available and you can save it in pdf format, that's it!
Now i would like to talk here how you can save it as PDF from C# code.
You need to first add Refernce of office introp dll as per shown in below figure.
And do code as per below...
usingMicrosoft.Office.Interop.Word;usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Text;...// Create a new Microsoft Word application objectMicrosoft.Office.Interop.Word.Applicationword =newMicrosoft.Office.Interop.Word.Application();// C# doesn't have optional arguments so we'll need a dummy valueobjectoMissing =System.Reflection.Missing.Value;// Get list of Word files in specified directoryDirectoryInfodirInfo =newDirectoryInfo(@"\\server\folder");FileInfo[] wordFiles = dirInfo.GetFiles("*.doc");word.Visible=false;word.ScreenUpdating=false;foreach(FileInfowordFileinwordFiles){// Cast as Object for word Open methodObjectfilename = (Object)wordFile.FullName;// Use the dummy value as a placeholder for optional argumentsDocumentdoc = word.Documents.Open(reffilename,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing);doc.Activate();objectoutputFileName = wordFile.FullName.Replace(".doc",".pdf");objectfileFormat =WdSaveFormat.wdFormatPDF;// Save document into PDF Formatdoc.SaveAs(refoutputFileName,reffileFormat,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,refoMissing);// Close the Word document, but leave the Word application open.// doc has to be cast to type _Document so that it will find the// correct Close method.objectsaveChanges =WdSaveOptions.wdDoNotSaveChanges;((_Document)doc).Close(refsaveChanges,refoMissing,refoMissing);doc =null;}// word has to be cast to type _Application so that it will find// the correct Quit method.((_Application)word).Quit(refoMissing,refoMissing,refoMissing);word =null;
You have to make change in above code as per your requirements.
 
 
 
No comments:
Post a Comment