1. public class Office2Pdf
  2. {
  3. public bool DOCConvertToPDF(string sourcePath, string targetPath)
  4. {
  5. //StreamReader reader = new StreamReader("temp.doc", Encoding.GetEncoding("gb2312"));
  6. //string text = reader.ReadToEnd();
  7. //Aspose.Words.Document doc = new Aspose.Words.Document();
  8. //Aspose.Words.DocumentBuilder builder = new DocumentBuilder(doc);
  9. //builder.Write(text);
  10. //doc.Save("temp.pdf", SaveFormat.Pdf);
  11. //reader.Close();
  12.  
  13. bool result = false;
  14. Word.WdExportFormat exportFormat = Word.WdExportFormat.wdExportFormatPDF;
  15. object paramMissing = Type.Missing;
  16. Word.ApplicationClass wordApplication = new Word.ApplicationClass();
  17.  
  18. Word.Document wordDocument = null;
  19. try
  20. {
  21. object paramSourceDocPath = sourcePath;
  22. string paramExportFilePath = targetPath;
  23. Word.WdExportFormat paramExportFormat = exportFormat;
  24. bool paramOpenAfterExport = false;
  25. Word.WdExportOptimizeFor paramExportOptimizeFor = Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
  26. Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
  27. int paramStartPage = ;
  28. int paramEndPage = ;
  29. Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
  30. bool paramIncludeDocProps = true;
  31. bool paramKeepIRM = true;
  32. Word.WdExportCreateBookmarks paramCreateBookmarks =
  33. Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
  34. bool paramDocStructureTags = true;
  35. bool paramBitmapMissingFonts = true;
  36. bool paramUseISO19005_1 = false;
  37. wordDocument = wordApplication.Documents.Open(
  38. ref paramSourceDocPath, ref paramMissing, ref paramMissing,
  39. ref paramMissing, ref paramMissing, ref paramMissing,
  40. ref paramMissing, ref paramMissing, ref paramMissing,
  41. ref paramMissing, ref paramMissing, ref paramMissing,
  42. ref paramMissing, ref paramMissing, ref paramMissing,
  43. ref paramMissing
  44. );
  45. if (wordDocument != null)
  46. wordDocument.ExportAsFixedFormat(
  47. paramExportFilePath, paramExportFormat, paramOpenAfterExport,
  48. paramExportOptimizeFor, paramExportRange, paramStartPage,
  49. paramEndPage, paramExportItem, paramIncludeDocProps,
  50. paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
  51. paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing
  52. );
  53. return true;
  54. }
  55. catch (Exception ex)
  56. {
  57. ex.WriteLog(ex.ToString());
  58. return false;
  59. }
  60. finally
  61. {
  62. if (wordDocument != null)
  63. {
  64. wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
  65. wordDocument = null;
  66. }
  67. if (wordApplication != null)
  68. {
  69. wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
  70. wordApplication = null;
  71. }
  72. GC.Collect();
  73. GC.WaitForPendingFinalizers();
  74. GC.Collect();
  75. GC.WaitForPendingFinalizers();
  76. }
  77. return result;
  78. }
  79. }

Excel转换成PDF的更多相关文章

  1. 多页Excel转换成PDF时如何保存为单独文件

    通过ABBYY PDF Transformer+图文识别软件,使用PDF-XChange打印机将多页Excel工作簿转换成PDF文档(相关文章请参考ABBYY PDF Transformer+从MS ...

  2. excel 转换成pdf 总结

    excl 转换成pdf 1.freespire   只能转换前三页 // 使用此组件 只能转换前3页 //需要引用 如下命名空间 //using Spire.Doc; //Document doc = ...

  3. python实现excel转换成pdf

    1.安装 需要安装pywin32包,以实现对Office文件的操作,可以批量转换为pdf文件.支持 doc, docx, ppt, pptx, xls, xlsx 等格式. pip install p ...

  4. word ppt excel文档转换成pdf

    1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...

  5. C#.net word excel powerpoint (ppt) 转换成 pdf 文件

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  6. C#实现文档转换成PDF

    网上有很多将doc.ppt.xls等类型的文档转换成pdf的方法,目前了解到的有两大类: 1.使用虚拟打印机将doc.ppt.xls等类型的文档 2.使用OFFICE COM组件 我采用了第二种方法实 ...

  7. c# office转换成pdf

    下载地址 [url]http://www.microsoft.com/downloads/details.aspx?FamilyId=4D951911-3E7E-4AE6-B059-A2E79ED87 ...

  8. C#将Word转换成PDF方法总结(基于Office和WPS两种方案)

    有时候,我们需要在线上预览word文档,当然我们可以用NPOI抽出Word中的文字和表格,然后显示到网页上面,但是这样会丢失掉Word中原有的格式和图片.一个比较好的办法就是将word转换成pdf,然 ...

  9. ASP.Net中实现上传过程中将文本文件转换成PDF的方法

    iTextSharp是一个常用的PDF库,我们可以使用它来创建.修改PDF文件或对PDF文件进行一些其他额外的操作.本文讲述了如何在上传过程中将文本文件转换成PDF的方法. 基本工作 在开始之前,我们 ...

随机推荐

  1. CSS:7个你可能不认识的单位

    原文:7 CSS Units You Might Not Know About 众所周知,当使用CSS技术的时候,很容被一些奇异问题给困住.而当我们面对新的问题时,这会让我们处于非常不利的位置. 但是 ...

  2. 线段相交 poj 1066

    // 线段相交 poj 1066 // 思路:直接枚举每个端点和终点连成线段,判断和剩下的线段相交个数 // #include <bits/stdc++.h> #include <i ...

  3. A题进行时--浙大PAT 1011-1020

    #include<stdio.h> #include<string.h> int main(){ ]; ]; ]; ]; ]; int i; float sum; memset ...

  4. java 中 正则 正则表达式 匹配 url

    不多说 [http|https]+[://]+[0-9A-Za-z:/[-]_#[?][=][.][&]]* 这个就是匹配 网络上的网址 又称 url . 最起码 绝大部分的taobao ur ...

  5. openstack 整合

  6. ColorNote.疑难解答

    首先感谢你对colornote的支持 在使用此应用的过程中,存在任何问题,请先在此页面查看是否有对应的解决方案[Ctrl + F 搜索] 如果问题无法解决,请在页面下方留言,或者邮件light.z@q ...

  7. iOS 使用FMDB SQLCipher给数据库加密

    关于SQLite,SQLCipher和FMDB SQLite是一个轻量的.跨平台的.开源的数据库引擎,它的在读写效率.消耗总量.延迟时间和整体简单性上具有的优越性,使其成为移动平台数据库的最佳解决方案 ...

  8. inline(内联函数)

    一般来说,调用函数会造成:目前的指令位置被存储下来,程序流跳转到所调用的函数,然后执行调用函数,最后跳转回之前存储的位置.对于需要常常调用的小函数来说,这会影响程序的运行效率.所以,c99新增了inl ...

  9. eclipse中如何设置tomcat启动时间

    现象:在eclipse中启动tomcat总是提示“Server Tomcat v5.5 Server @ localhost was unable to start within 45 seconds ...

  10. CentOS 下安装操作Memcached

    Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...