Every day is a new day. Hello, technology curtilages.
Recently I have received several small projects and want to prepare for the exam. So I didn't write any big projects, but some functional modules. A few days ago, I found that the download technical documentation area of BKJIA has a preview function. It feels good. Although I don't know how to write it, It is very convenient. I didn't pay much attention to the code until I got a "job" and found that I had to do the same function. I felt dumb at the time. Where can I do this? But there is no way, the next thing cannot be returned! I searched for nearly a hundred webpages on the Internet that day and found three popular websites: Print2Flash, FlexPaper + SWFTools, and flash2paper.
First, flash2paper. This version supports 32-bit systems and does not support 64-bit systems. However, it was widely used in the past and is now in the "XP" stage. PASS! Then there is Print2Flash, which is still widely used at present, but there is a drawback that it will automatically generate a virtual printer in the system, at that time, you need to modify and set up the printer when you are working. It is very troublesome, if you are a little white. PASS! Finally, we chose FlexPaper + SWFTools, which is the same as BKJIA. After finding a world, I finally returned to my hometown. Very kind! 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123H95F2-0.gif "alt =" C_0004.gif "/>
Online Preview document principle: convert any files you upload into a format that can be recognized by flash players, that is, swf playback. The effect is document preview. I understand the truth, but if you do it, you may not be able to beat the enemy with a single trick. I have a deep understanding of the later debugging. Although I have been holding this thing for two days, it is very difficult to do so because I have not eaten or drank water. Because I have never touched such a thing, the learning process is my own thing.
In the following tutorial, I will first look at the BKJIA writing format:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123H95622-1.jpg "title =" 8QGR) 3JJ ~ Tweobstmsewblhe2.jpg "alt =" 0000000710.jpg"/>
Get familiar with FlexPaper attribute settings and find the url for passing values, for example,
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123H9C51-2.png "title =" QQ20131206104637.png "alt =" 104640840.png"/>
In this way, we will probably understand the FlexPaper configuration. Next, let's look at SWFTools. This is to convert the pdf document to swf in a unified manner. In this way, the idea will come out, give a judgment when uploading,
If (fileExt = ". doc "| fileExt = ". docx ") {office2pdf. DOCConvertToPDF (sourcePath, targetPath);} if (fileExt = ". ppt "| fileExt = ". pptx ") {office2pdf. PPTConvertToPDF (sourcePath, targetPath);} if (fileExt = ". xlsx "| fileExt = ". xls ") {office2pdf. XLSConvertToPDF (sourcePath, targetPath);} if (fileExt = ". pdf ") {// No processing}
You can convert the document format of the office to pdf, and then use swftools to convert it to swf to preview the document. It seems very simple to say, but if you do, there will be many problems.
Next, I will introduce you to the office2pdf conversion method: You need to reference four dll files: Microsoft. office. interop. excel, Microsoft. office. interop. powerPoint, Microsoft. office. interop. word, office.
Using System; using System. data; using System. configuration; using System. web; using System. web. security; using System. web. UI; using System. web. UI. webControls; using System. web. UI. webControls. webParts; using System. web. UI. htmlControls; using Word = Microsoft. office. interop. word; using Excel = Microsoft. office. interop. excel; using PowerPoint = Microsoft. office. interop. powerPoint; using Microsoft. office. core; nam Espace Document_preview.commonClass {// <summary> // Office2Pdf converts the Office document to pdf // </summary> public class Office2Pdf {public Office2Pdf () {// TODO: add the constructor logic here // <summary> // Word to pdf /// </summary> /// <param name = "sourcePath"> source file path </param> /// <param name = "targetPath"> target file path </param> /// <returns> true = Conversion successful </returns> public bool DOCConvertToPDF (string sourcePath, string targetPa Th) {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 paramOpenAfte RExport = false; Word. wdExportOptimizeFor paramExportOptimizeFor = Word. wdExportOptimizeFor. wdExportOptimizeForPrint; Word. wdExportRange paramExportRange = Word. wdExportRange. wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0; Word. wdExportItem paramExportItem = Word. wdExportItem. wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramkeepsert = true; Word. wdExportCreate Bookmarks paramCreateBookmarks = Word. wdExportCreateBookmarks. wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; wordDocument = wordApplication. documents. open (ref paramSourceDocPath, ref paramMissing, ref par AmMissing, ref paramMissing, ref paramMissing); if (wordDocument! = Null) wordDocument. parameters (paramExportFilePath, paramExportFormat, parameters, parameters, paramExportRange, paramStartPage, paramEndPage, paramExportItem, parameters, paramkeepsert, paramCreateBookmarks, parameters, ref paramMissing); result = true ;} catch {result = false;} finally {if (wordDoc Ument! = 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 ;} /// <summary> /// convert an Excel file to a PDF file // </summary> /// <param name = "sourcePath"> source file path </param> /// <param name = "targetPath"> target file path </param> /// <returns> true = Conversion successful </returns> public B Ool XLSConvertToPDF (string sourcePath, string targetPath) {bool result = false; Excel. xlFixedFormatType targetType = Excel. xlFixedFormatType. xlTypePDF; object missing = Type. missing; Excel. applicationClass application = null; Excel. workbook workBook = null; try {application = new Excel. applicationClass (); object target = targetPath; object type = targetType; workBook = application. workbooks. open (SourcePath, missing); workBook. exportAsFixedFormat (targetType, target, Excel. xlFixedFormatQuality. xlQualityStandard, true, false, 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 ;} /// <summary> /// convert a PowerPoint file to a PDF file // </summary> /// <param name = "sourcePath"> source file path </param >/// <param name = "targetPath"> target file path </param> /// <returns> true = Conversion successful </returns> public bool PPTConvertToPDF (string sourcePath, string targetPath ){ Bool result; PowerPoint. ppSaveAsFileType targetFileType = PowerPoint. ppSaveAsFileType. ppSaveAsPDF; object missing = Type. missing; PowerPoint. applicationClass application = null; PowerPoint. presentation persentation = null; try {application = new PowerPoint. applicationClass (); persentation = application. presentations. open (sourcePath, MsoTriState. msoTrue, MsoTriState. msoFalse, MsoTriState. msoFalse); Persentation. SaveAs (targetPath, targetFileType, Microsoft. Office. Core. 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 ;}}}
After the writing class is called, The format is office2pdf. DOCConvertToPDF (sourcePath, targetPath ).
After converting office2pdf, you can use swftools to export 2swf.
string fileName = ViewState["fileName"].ToString(); string cmdStr = HttpContext.Current.Server.MapPath("~/SWFTools/pdf2swf.exe"); string savePath = HttpContext.Current.Server.MapPath("~/WordManage/word/"); //string aa = DateTime.Now.ToString("yyyymmddhhmmss"); string sourcePath = @"""" + savePath + TextBox11.Text.ToString() + ".pdf" + @""""; string targetPath = @"""" + savePath + TextBox11.Text.ToString() + ".swf" + @""""; string argsStr = " -t " + sourcePath + " -s flashversion=9 -o " + targetPath; ExcutedCmd(cmdStr, argsStr);
After the upload is complete, we will find the file, for example, in the root directory,
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123H91115-3.png "title =" QQ20131206110457.png "alt =" 110527596.png"/>
Finally, combined with the Bootstrap pop-up layer, you can make an effect as shown in the following figure,
650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123H91507-4.jpg "title =" qq 31206110621.jpg "width =" 800 "height =" 430 "border =" 0 "hspace =" 0 "vspace =" 0 "style =" width: 800px; height: pixel PX; "alt =" 110659684.jpg"/>
I don't know how you feel. I have been holding for two days, and I feel that this effect can be achieved. I am a person who is easy to satisfy. Finally, I would like to thank my mentor for asking me about the things of eating, drinking, and Lazarus every day. I am also a teacher and mother! It can make the world's parents heart, only by working hard to become a challenge, huh, huh. (Then I will upload the demo to the project independently)
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123H93118-5.jpg "title =" qi1.jpg "alt =" 110919270.jpg"/>
Demo: http://down.51cto.com/data/1052309
This article is from the "Liang Xiao Technology Center" blog, please be sure to keep this source http://liangxiao.blog.51cto.com/3626612/1337374