C# .NET - how to microsoft word document (doc) format to pdf format

Asked By srini vasan on 10-May-11 02:05 AM
how to microsoft word document (doc) format to pdf format 
Ravi S replied to srini vasan on 10-May-11 02:07 AM
HI

use this code

private Microsoft.Office.Interop.Word.ApplicationClass MSdoc;     
     
      //Use for the parameter whose type are not known or say Missing
      object Unknown = Type.Missing;

  private void word2PDF(object Source, object Target)
      {
   //Creating the instance of Word Application      
     if (MSdoc == null)MSdoc = new Microsoft.Office.Interop.Word.ApplicationClass();
       
        try
        {  
          MSdoc.Visible = false;         
          MSdoc.Documents.Open(ref Source, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
          MSdoc.Application.Visible = false;
          MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;         
                         
          object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
                 
          MSdoc.ActiveDocument.SaveAs(ref Target, ref format,
              ref Unknown, ref Unknown, ref Unknown,
              ref Unknown, ref Unknown, ref Unknown,
              ref Unknown, ref Unknown, ref Unknown,
              ref Unknown, ref Unknown, ref Unknown,
             ref Unknown, ref Unknown);

        }
        catch (Exception e)
        {
          MessageBox.Show(e.Message);
        }
        finally
        {
          if (MSdoc != null)
          {
            MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown);
            //WordDoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown);
          }         
          // for closing the application
          WordDoc.Quit(ref Unknown, ref Unknown, ref Unknown);
        }
      }


refer the link
http://www.codeproject.com/KB/cs/convertdocintootherformat.aspx
Reena Jain replied to srini vasan on 10-May-11 02:10 AM
hi,

here is two good link on this

http://www.codeproject.com/KB/cs/sertf2pdf.aspx
http://social.msdn.microsoft.com/Forums/en/vsto/thread/f8989c05-d04a-4b4a-be0f-fc0055691de7

Hope this will help you
S replied to srini vasan on 10-May-11 07:02 AM
  1. Click the Microsoft Office ButtonButton image, point to the arrow next to Save As, and then click PDF or XPS.
  2. In the File Name list, type or select a name for the document.
  3. In the Save as type list, click PDF.
  4. If you want to open the file immediately after saving it, select the Open file after publishing check box. This check box is available only if you have a PDF reader installed on your computer.
  5. Next to Optimize for, do one of the following, depending on whether file size or print quality is more important to you:
    • If the document requires high print quality, click Standard (publishing online and printing).
    • If the print quality is less important than file size, click Minimum size (publishing online).
  6. Click Options to set the page range to be printed, to choose whether markup should be printed, and to select the output options. (Find links to more information on these options in the See Also section.) Click OK.
  7. Click Publish.