public  class Office2Pdf
{
public bool DOCConvertToPDF(string sourcePath, string targetPath)
{
//StreamReader reader = new StreamReader("temp.doc", Encoding.GetEncoding("gb2312"));
//string text = reader.ReadToEnd();
//Aspose.Words.Document doc = new Aspose.Words.Document();
//Aspose.Words.DocumentBuilder builder = new DocumentBuilder(doc);
//builder.Write(text);
//doc.Save("temp.pdf", SaveFormat.Pdf);
//reader.Close(); bool result = false;
Word.WdExportFormat exportFormat = Word.WdExportFormat.wdExportFormatPDF;
object paramMissing = Type.Missing;
Word.ApplicationClass wordApplication = new Word.ApplicationClass(); Word.Document wordDocument = null;
try
{
object paramSourceDocPath = sourcePath;
string paramExportFilePath = targetPath;
Word.WdExportFormat paramExportFormat = exportFormat;
bool paramOpenAfterExport = false;
Word.WdExportOptimizeFor paramExportOptimizeFor = Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
int paramStartPage = ;
int paramEndPage = ;
Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
Word.WdExportCreateBookmarks paramCreateBookmarks =
Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;
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
);
if (wordDocument != null)
wordDocument.ExportAsFixedFormat(
paramExportFilePath, paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing
);
return true;
}
catch (Exception ex)
{
ex.WriteLog(ex.ToString());
return false;
}
finally
{
if (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
wordDocument = null;
}
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
wordApplication = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
}
}

最新文章

  1. SerialPort 串口开发
  2. 处理bin文件
  3. vue.js 1中父组件跳到子组件中并传参让子组件显示不同的内容
  4. here 文档
  5. 兼容的firstChild,lastChild,nextSibling,previousSibling写法
  6. VirtualBox网络设置讲解
  7. 关于VSTO调用Excel后进程无法退出的解决方案:
  8. HDU 2577 How to Type(dp题)
  9. jQuery的deferred对象
  10. page cache 与 page buffer 转
  11. LeetCode 122
  12. DenyHosts限制SSH登录尝试次数
  13. angular在ie8下的一个bug
  14. 详解go语言的array和slice 【一】
  15. RESTful 最佳实战
  16. 多线程手写Future模式
  17. 在Windows上使用Let加密IIS
  18. bzoj1668
  19. .net如何处理高并发socket,建立高性能健壮的socket服务
  20. 【C语言】十六进制形式输出应用程序

热门文章

  1. XCode修改工程名注意
  2. WebStorm2016.1 破解 激活
  3. schema对象介绍
  4. python 入门实践之网页数据抓取
  5. bzoj 2599 [IOI2011]Race (点分治)
  6. bfs CCF2016第七次 游戏
  7. Python学习笔记——正则表达式
  8. Fast Intro To Java Programming (1)
  9. [iOS微博项目 - 1.5] - NavigationBar标题按钮
  10. [iOS基础控件 - 6.11.5] 沙盒 & 数据存储