Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be able to do it with the express version. I adapted an answer to <a href="https://stackoverflow.com/questions/607669/how-do-i-convert-word-files-to-pdf-programmatically">this question</a>. The adapted code is below. You'll need to add a reference to Microsoft.Office.Interop.Word for this to work. If you're missing this library, have a look at <a href="http://msdn.microsoft.com/en-us/library/15s06t57(v=vs.100).aspx" rel="nofollow noreferrer">this article on MSDN</a>.</p> <p>Looking at <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat.aspx" rel="nofollow noreferrer">WdSaveFormat</a> you can also save it as Format Filtered HTML (wdFormatFilteredHTML).</p> <pre><code>namespace Sample { using Microsoft.Office.Interop.Word; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; class Program { public static void Main() { Convert("C:\\Documents", WdSaveFormat.wdFormatHTML); } private static void Convert(string path, WdSaveFormat format) { DirectoryInfo dirInfo = new DirectoryInfo(path); FileInfo[] wordFiles = dirInfo.GetFiles("*.doc"); if (wordFiles.Length == 0) { return; } object oMissing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); try { word.Visible = false; word.ScreenUpdating = false; foreach (FileInfo wordFile in wordFiles) { Object filename = (Object)wordFile.FullName; Document doc = word.Documents.Open(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); try { doc.Activate(); object outputFileName = wordFile.FullName.Replace(".doc", ".html"); object fileFormat = format; doc.SaveAs(ref outputFileName, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); } finally { object saveChanges = WdSaveOptions.wdDoNotSaveChanges; ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing); doc = null; } } } finally { ((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing); word = null; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload