#region word转为图片
public void GetImages(string SourceDocPath, string ExportFilePath)
{
object paramSourceDocPath = SourceDocPath;
string paramExportFilePath = ExportFilePath;
object paramMissing = Type.Missing;
ApplicationClass wordApplication = new ApplicationClass();
wordApplication.Visible = false;
Document wordDocument = null;
WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
bool paramOpenAfterExport = false;
WdExportOptimizeFor paramExportOptimizeFor =
WdExportOptimizeFor.wdExportOptimizeForPrint;
WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
int paramStartPage = 0;
int paramEndPage = 0;
WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
WdExportCreateBookmarks paramCreateBookmarks =
WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;
try
{
// Open the source document.
wordDocument = wordApplication.Documents.Open(
ref paramSourceDocPath, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing);
// Export it in the specified format.
string expFileName = paramExportFilePath + "word.pdf";
if (wordDocument != null)
wordDocument.ExportAsFixedFormat(expFileName,
paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1,
ref paramMissing);
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName = "cmd.exe";
//设置外部程序的启动参数(命令行参数)为test.txt
Info.Arguments = "/c convert.exe word.pdf " + paramExportFilePath + "p%d.png";
//设置外部程序工作目录为
Info.WorkingDirectory = paramExportFilePath;
Info.UseShellExecute = true;
//声明一个程序类
System.Diagnostics.Process Proc ;
try
{
//
//启动外部程序
//
Proc = System.Diagnostics.Process.Start(Info);
}
catch(System.ComponentModel.Win32Exception e)
{
//MessageBox.show();
string aa = e.Message;
}
int pngNum = 0;
string tempFileName = paramExportFilePath + "p" + pngNum + ".png";
while(true)
{
if(!File.Exists(tempFileName))
break;
pngNum++;
tempFileName = paramExportFilePath + "p" + pngNum + ".png";
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// Close and release the Document object.
if (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing,
ref paramMissing);
wordDocument = null;
}
// Quit Word and release the ApplicationClass object.
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing,
ref paramMissing);
wordApplication = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
#endregion