word,excel,ppt转Pdf,Pdf转Swf,通过flexpaper+swftools实现在线预览

其实这是我好几年前的项目,现在再用这种方式我也不建议了,毕竟未来flash慢慢会淘汰,此方式也是因为目测大部分人都装了flash,才这么做的,但是页面展示效果也不好。其实还是考虑收费的控件,毕竟收费的还是做的不错的!

而且此方式服务器要安装office组件,项目实施也不好!

以上为最新更新建议!

自己上网查了好多种方法,最后还是选了这种不收费,还挺好用的方法

           为了用户有一个好的体验我将wordexcel、ppt转Pdf,Pdf转Swf写在服务上,因为我当时做的时候Pdf转Swf会执行pdf2swf.exe弹出黑框,对用户体验不好,还有就是ppt转swf时会有一个弹出框,提示正在发布,我没搞明白,就把他们都写在服务上了。

Office2Pdf

word,excel,ppt转Pdf,Pdf转Swf,通过flexpaper+swftools实现在线预览

word,excel,ppt转Pdf,Pdf转Swf,通过flexpaper+swftools实现在线预览

/// <summary> /// Office2Pdf 将Office文档转化为pdf /// </summary> public class Office2PDFHelper { public Office2PDFHelper() { // // TODO: 在此处添加构造函数逻辑 // } #region 1.0 Word转换成pdf + bool DOCConvertToPDF(string sourcePath, string targetPath) /// <summary> /// Word转换成pdf /// </summary> /// <param>源文件路径(物理路径)</param> /// <param>目标文件路径(物理路径)</param> /// <returns>true=转换成功</returns> public static bool DOCConvertToPDF(string sourcePath, string targetPath) { // string targetPath = "G:\\工作\\ceshi\\ceshi.pdf"; // sourcePath = "G:\\工作\\OfficePreview\\Preview\\SourceFile\\测试.doc"; bool result = false; Word.WdExportFormat exportFormat =http://www.likecs.com/ Word.WdExportFormat.wdExportFormatPDF; object paramMissing =http://www.likecs.com/ Type.Missing; Word.ApplicationClass wordApplication = new Word.ApplicationClass(); Word._Document wordDocument = null; try { object paramSourceDocPath =http://www.likecs.com/ sourcePath; string paramExportFilePath =http://www.likecs.com/ targetPath; Word.WdExportFormat paramExportFormat =http://www.likecs.com/ exportFormat; bool paramOpenAfterExport = false; Word.WdExportOptimizeFor paramExportOptimizeFor =http://www.likecs.com/ Word.WdExportOptimizeFor.wdExportOptimizeForPrint; Word.WdExportRange paramExportRange =http://www.likecs.com/ Word.WdExportRange.wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0; Word.WdExportItem paramExportItem =http://www.likecs.com/ Word.WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true; Word.WdExportCreateBookmarks paramCreateBookmarks =http://www.likecs.com/ Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; wordDocument =http://www.likecs.com/ 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); result = true; } catch { result = 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; } #endregion #region 2.0 把Excel文件转换成PDF格式文件 + 把Excel文件转换成PDF格式文件 /// <summary> /// 把Excel文件转换成PDF格式文件 /// </summary> /// <param>源文件路径(物理路径)</param> /// <param>目标文件路径(物理路径)</param> /// <returns>true=转换成功</returns> public static bool XLSConvertToPDF(string sourcePath, string targetPath) { bool result = false; Excel.XlFixedFormatType targetType =http://www.likecs.com/ Excel.XlFixedFormatType.xlTypePDF; object missing =http://www.likecs.com/ Type.Missing; Excel.ApplicationClass application = null; Excel.Workbook workBook = null; try { application = new Excel.ApplicationClass(); object target =http://www.likecs.com/ targetPath; object type =http://www.likecs.com/ targetType; workBook =http://www.likecs.com/ application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); workBook.ExportAsFixedFormat(targetType, target, Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing); result = true; } catch { result = false; } finally { if (workBook != null) { workBook.Close(true, missing, missing); workBook = null; } if (application != null) { application.Quit(); application = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } return result; } #endregion #region 3.0 把PowerPoint文件转换成PDF格式文件 + bool PPTConvertToPDF(string sourcePath, string targetPath) ///<summary> /// 把PowerPoint文件转换成PDF格式文件 ///</summary> ///<param>源文件路径(物理路径)</param> ///<param>目标文件路径(物理路径)</param> ///<returns>true=转换成功</returns> public static bool PPTConvertToPDF(string sourcePath, string targetPath) { bool result; PowerPoint.PpSaveAsFileType targetFileType =http://www.likecs.com/ PowerPoint.PpSaveAsFileType.ppSaveAsPDF; object missing =http://www.likecs.com/ Type.Missing; PowerPoint.ApplicationClass application = null; PowerPoint.Presentation persentation = null; try { application = new PowerPoint.ApplicationClass(); //打开 persentation =http://www.likecs.com/ application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); if (persentation != null) { //写入 persentation.SaveAs(targetPath, targetFileType, MsoTriState.msoTrue); } result = true; } catch { result = false; } finally { if (persentation != null) { persentation.Close(); persentation = null; } if (application != null) { application.Quit(); application = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } return result; } #endregion }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzpdys.html