C# 仿百度文库实现方法(已测试可行)
《C# 仿百度文库实现方法(已测试可行)》由会员分享,可在线阅读,更多相关《C# 仿百度文库实现方法(已测试可行)(11页珍藏版)》请在装配图网上搜索。
1、C# 仿百度文库在线查看功能资料发布到查看分为三个步骤:1、上传文件(doc、xls、ppt)转换成Pdf文件2、Pdf文件转换成swf文件3、把 swf 文件显示出来第一步:把上传的文件(doc、xls、ppt)转换成Pdf文件。直接在后台用代码转 换,新建一个类,这一步没有什么特殊的要求,转换代码如下:using System;using System.Data;usi ng System.C on figura tion;using System.Web;using System.Web.Security;us ing System.Web.UI;using System.Web.Ul.
2、WebControls;usi ng System.Web.UI.WebC on trols.WebParts;using System.Web.UI.HtmlC on trols;us ing Word = Microsoft.Office .In terop.Word;usi ng Excel = Microsoft.Office .In terop.Excel;usi ng PowerPo int = Microsoft.Office .In terop.PowerPo int;us ing Microsoft.Office.Core;us ing System.Collec tion
3、s.Ge neric;usi ng System.L inq;/注:/usi ng Word = Microsoft.Office.I nterop.Word;/us ing Excel = Microsoft.Office .In terop.Excel;/usi ng PowerPo int = Microsoft.Office .In terop.PowerPo int;/上面三个引用在添加引用的.NET标签中/ usi ng Microsoft.Office.Core;上面这个引用在添加引用COM中的 Microsoft Office 12.0 Object Library/ /Off
4、ice2Pdf的摘要说明/ public class Office2Pdf/ / Word 转换成 pdf/ / vparam name=sourcePath 源文件路径 v/param/ vparam name=targetPath 目标文件路径 v/param/ vretur nstrue=转换成功 v/retur nspublic bool DOCConvertToPDF(string sourcePath, string targetPath) bool result = false;Word.WdExportFormat exportFormat =Word.WdExportForm
5、at.wdExportFormatPDF;object paramMiss ing = Type.Miss ing;Word.Applica tion Class wordApplica tion = new Word.Applica tion Class();Word.Docume nt wordDocume nt = n ull;tryobject paramSourceDocPath = sourcePath; stri ng paramExportFilePath = targetPath; Word.WdExportFormat paramExportFormat = exportF
6、ormat; bool paramOpe nAfterExport = false;Word.WdExportOp ti mizeFor paramExportOp timizeFor = Word.WdExportOp ti mizeFor.wdExportOp ti mizeForPri nt;Word.WdExportRa nge paramExportRa nge =Word.WdExportRa nge.wdExportAllDocume nt;int paramStartPage = 0;int paramE ndPage = 0;Word.WdExportItem paramEx
7、portItem =Word.WdExportItem.wdExportDocume ntContent;bool param In cludeDocProps = true; bool paramKeepIRM = true;Word.WdExportCreateBookmarks paramCreateBookmarks = Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;bool paramDocStructureTags = true; bool paramBitmapMiss ingFonts = true; bool
8、 paramUselS019005_1 = false;wordDocume nt = wordApplica tion .Docume nts.Ope n(ref paramSourceDocPath, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref par
9、amMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMiss ing, ref paramMissi ng);if (wordDocume nt != n ull)wordDocume nt.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpe nAfterExport,paramExportOp ti mizeFor, paramExportRa nge,paramStartPage,paramE ndPage, paramExportItem
10、, param In cludeDocProps, paramKeepIRM, paramCreateBookmarks,paramDocStructureTags,paramBitmapMissi ngFo nts, paramUselS019005_1,ref paramMissi ng);result = true;catchresult = false;fin allyif (wordDocume nt != n ull)wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissi ng);wordDocum
11、e nt = n ull;if (wordApplica tion != n ull)wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissi ng);wordApplica tion = n ull;GC.Collect();GC.WaitForPe ndin gFi nalizers();GC.Collect();GC.WaitForPe ndin gFi nalizers();return result;/ /把Excel文件转换成PDF格式文件/ / 源文件路径 v/param/ 目标文件路径 v/p
12、aram/ true=转换成功 v/retur nspublic bool XLSConvertToPDF(string sourcePath, string targetPath) bool result = false;Excel.XlFixedFormatType targetType = Excel.XlFixedFormatType.xlTypePDF; object missi ng = Type.Missi ng;Excel.Applica tion Class applica tion = n ull;Excel.Workbook workBook = n ull;tryapp
13、lica tion = new Excel.Applica tion Class();object target = targetPath; object type = targetType;workBook = applica tion. Workbooks.Ope n( sourcePath, miss ing,missi ng, missi ng, missi ng, missi ng,missi ng, missi ng, miss ing, miss ing, miss ing, miss ing, missi ng, missi ng, missi ng);workBook.Exp
14、ortAsFixedFormat(targetType, target, Excel.XlFixedFormatQuality.xlQualitySta ndard, true, false, miss ing, miss ing, miss ing, missi ng);result = true;catch result = false;fin allyif (workBook != null)workBook.Close(true, miss ing, missi ng); workBook = n ull;if (applica tion != n ull)applica tion.
15、Quit(); applica tion = n ull;GC.Collect();GC.WaitForPe ndin gFi nalizers();GC.Collect();GC.WaitForPe ndin gFi nalizers();return result;/vsummary/把PowerPoint文件转换成PDF格式文件 / 源文件路径 v/param/ 目标文件路径 v/param /true=转换成功 v/retur nspublic bool PPTConvertToPDF(string sourcePath, string targetPath) bool result;
16、PowerPo in t.PpSaveAsFileType targetFileType =PowerPoi nt.PpSaveAsFileType.ppSaveAsPDF;object missi ng = Type.Missi ng;PowerPo in t.Applica tion Class applica tion = n ull;PowerPo in t.Prese nta tion perse ntation = n ull;tryapplica tion = new PowerPo in t.Applica tion Class();perse ntation = applic
17、a tion .Prese nta tion s.Ope n( sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); perse ntati on. SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);result = true;catchresult = false;fin allyif (perse nta tion != n ull)perse ntation. Close();per
18、se nta tion = n ull;if (applica tion != n ull)applica tion. Quit();applica tion = n ull;GC.Collect();GC.WaitForPe ndin gFi nalizers();GC.Collect();GC.WaitForPe ndin gFi nalizers();return result;第二步:Pdf文件转换成swf文件,这里需要借用到swftools这个软件下面的 pdf2swf.exe,上网找到swftools-2013-04-09-1007,下载下来安装一下,在安装好 的目录如下: tf且
19、1 *(D: k 5!AHftD0lE t.rxe-unin-stall.e-YE-kJI sfbbos.exe -l sivfc.ext *1 swfrt! mbine.益M日Limp.亡住亡 1 fifextractesejj. pythcHi24.pylhon25.pyfhon26 百理f呂 viewers I a&3cornpik.ex- gpdf2&wf. exe焙改日明丈小2013-LL-12 13:092013-LL-12 13:092013-11422013-11-12 13:092013-11-13 &162013-LL-12 13:092013-1142 13:M2013-
20、11422013-11-12 13:092013-LL-12 13:092013-LL-12 13:092013-11-12 IMS201341-12 13:0a2013-11-12 IMS2013-EL-12 13:092013-11422013-1142 13:092013-11-12 13:092013-LL-12 13:09文件夹 轴夹 S:件去应用程序 应弔?2.016 KB575 KB应勰*靈(j左晋I:占刪应用程序翻?JEdLffiar应擁序16,532 KB4-22 Kfl6.3 3J KB妞9 KB5 KB515 KB3.D33 KH2.297 KB2013-LL-12 L3
21、;09.S用序2013-11-li2013-11-12 13; W 虫弔師78 KB562 KB,接下来转换过程中还要用到一个字库来保证转换成功。 准备资料:1. xpdfbin-win-3.03.zip、xpdf-chinese-simplified.tar.gz下载地址:2.两个中文字体文件: gkai00mp.ttf、Gbsn00lp.ttf下载地址:2&q=3.加上 PDF2SWF 工具 http:/www.swftools.org/download.html 下面集中精力解决中文字符的问题。1. 解压缩 xpdfbin-win-3.03.zip 到指定目录(C:xpdf)2. 解压缩
22、 xpdf-chinese-simplified.tar.gz 到上面的目录下 (C:xpdfxpdf-chinese-simplified)3. 拷贝两个字体文件gkaiOOmp.ttf、Gbsn0Olp.ttf到CMap目录下 (C:xpdfxpdf-chinese-simplifiedCMap)4. 修改 C:xpdfxpdf-chinese-simplified 下的 add-to-xpdfrc 文件注意相关路径配 置,如下图:radd-TO-updfrc -记事疋交件(El 礙巳搭式1口宜芝沮希切且I*begin CkircsL Zinplificd 3jpport pacl:3jc
23、 ,2(ill-Gcp-)2,cicloLlni 2ode nri rndplff 可) Lu.icudelrt ip Lii.icodcip cipLlir TrTri cird三Tj; tAdo?e-Ghl ISO-2D22-CN ELC-CXCBKAdo?e-Ghl-:/zpdf/ cbin=5e 7: Apdf/ chi n=: m p d/_h i “二七 二:/xp lf/ chi L13 5 u _ : /zpdf/ chin?se 7:: y-rpdf/ rhi n = =:=sinpliii d-Adobe-GBl. ci d.oUni code sirnolified/IS
24、O-2022-CN. unj codeMaa? bii.inllllzid-EUC-GN. uiiiL: jleNap sinjzlifisdCEE. ui-icodsMap ginplitidCNap sinrl i fi =d/CTai.displace I DFontTT Adobe-GB1 displayCIDFontTT Adobe CB13: ,zxpdf/judf-jiiliicat-tiLLDLiilcd/CNdp/=all!0(i.in. Ilf 3: /Apdf/spdf shine sc EiiiiDLificd/CNap/bsiiOtil;. ttfr rk?ig =匸
25、=|1 (hir.F!=F; ti fc接下来就是正式的转换了,新建个类,这下面的代码和上面转 Pdf 的代码所传 递的文件路径都为绝对地址,如:D: /aa/aa.doc等,转换后的路径也一样,把 文件名一起写上去。转换代码如下:using System;using System.Data;usi ng System.C on figura tion;using System.Web;using System.Web.Security;us ing System.Web.UI;using System.Web.Ul.WebControls;usi ng System.Web.UI.WebC
26、on trols.WebParts;using System.Web.UI.HtmlC on trols;using System.Diag no stics;using System .10;using System.Text;/ /Pdf2Swf的摘要说明/ public class Pdf2Swfpublic void PDFConvertToSWF(string pdfPath, string swfPath) string exe = D:/swftools/pdf2swf.exe; pdf2swf.exe的安装地址Stri ngBuilder sb = new Str in gBu
27、ilder();sb.Appe nd( + pdfPath + );/i nputsb.Appe nd( -o + swfPath + );/outputsb.Append( -s flashversion=9);/flash versionsb.Append( -j 100);/SWF 中的图片质量string Comma nd = sb.ToString();System.Diagnostics.Process p = new System.Diagnostics.Process();p.StartI nfo .FileName = exe;p.StartI nf o.Argume nts
28、 = Comma nd;p.StartI nf o.Worki ngDirectory=HttpCo ntext.Curre nt.Server.MapPath(/Bi n/);p.Start In fo.UseShellExecute = false;/不使用操作系统外壳程序启动线程p.StartInfo.RedirectStandardError = true;/把外部程序错误输 出写到 StandardError流中(这个一定要注意pdf2swf.exe的所有输出信息都为错误输出流, 用? StandardOutput是捕获不到任何消息的p.StartI nf o.CreateNoWi
29、ndow = true;/不 创建进程窗口p.Start();/启动线程p.Beg in ErrorReadLi ne(); 开始异步读取p.WaitForExit();等待完成p.Close();/关闭进程p.Dispose(); 释放资源第三步:把 swf 文件显示出来,这里面要用到 FlexPaper,FlexPaper 在 google code 上的下载地址为http:/code.google.eom/p/flexpaper/。目前使用的版本为,这个 测试过比较稳定 FlexPaper_1.5.1_flash.zip。下载、解压后,可以看到如下的目录:FileShow. a spje
30、垒二FlexPa perVi ewer.swfPa per. surfplayer Prod u ctln sta 11. suxfT在head中引入下面那个JS 接着把显示的主体,代码如下vbodyvdiv class=FileShow_2v/avscript type=text/javascriptvar fp = new FlexPaperViewer(FlexPaperViewer, viewerPlaceHolder: con fig: SwfFile:v%=wenjian %,/此处放你要显示的SWF文件的地址 Scale: 0.6,ZoomTra nsi tion: easeOu
31、t,ZoomTime: 0.5,Zoom In terval: 0.2,FitPage On Load: true,FitWidthOnLoad: true,FullScree nAsMaxWi ndow: false,ProgressiveLoad in g: false,Min ZoomSize: 0.2,MaxZoomSize: 5,SearchMatchAll: false,In itViewMode: Portrait,ViewModeToolsVisible: true,ZoomToolsVisible: true,NavToolsVisible: true,CursorToolsVisible: true,SearchToolsVisible: true,localeCha in: zh_CN -);
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《认识角》ppt教学讲解课件
- 《从数据谈节水》数据的收集、整理与描述优秀教学ppt课件
- 人员配置-公司组织架构与人员配置计划课件
- 《认识分式》ppt课件
- 《从百草园到三味书屋》第一课时ppt课件
- 公路工程概预算三课件
- 中考物理专题突破-综合能力题教学课件
- 《创新设计》高考英语二轮复习(江苏专用)ppt课件:第二部分-基础语法巧学巧练-专题八-非谓语动词
- 中考物理专题复习课件:滑轮及滑轮组
- CIM安全标识统一规划课件
- 中考物理专题复习教学课件-质量和密度
- 《处理民族关系的原则平等团结共同繁荣》ppt课件
- 中考物理专题复习之物理实验和探究题复习指导教学课件
- 《十二人人都会有挫折》初中心理健康教育闽教版《中学生心理健康》七级课件
- Cisco无线网络-安全-Brief课件