Several implementation methods of online document preview

Source: Internet
Author: User
Tags pdfobject

1 A way to compare old Aspose.dll+swftool+flexpaper

You can implement an online preview of the Excel table World document PDF file.

First, use Aspose to convert the file to PDF format. Aspose.words is an advanced class library that allows you to perform a variety of document processing tasks directly in each application. It contains several major DLL components that can manipulate different format files, and we mainly use Aspose.worlds and aspose.cells. In fact, they can achieve more complex file generation and operation, but I only use their file format conversion function here. I downloaded the cracked version of Aspose. Bring these two DLLs into your project. Write a method to convert the format.

 public class Asposehelper {//Convert Word document to PDF public static bool Getpdffromword (string soursefilepath, str  ing Outpdfpath) {//Read Word document try {using (System.IO.Stream Stream =                    New System.IO.FileStream (Soursefilepath, FileMode.Open, FileAccess.Read, Fileshare.readwrite)) {                    Aspose.Words.Document doc = new Aspose.Words.Document (Soursefilepath); Doc.                    Save (Outpdfpath, ASPOSE.WORDS.SAVEFORMAT.PDF);                return true;            }} catch (Exception ex) {return false;        }}//excel document conversion issue public static bool Getpdffromexcel (string Soursefilepath, String outpdfpath) {try {using (System.IO.Stream Stream = new System.IO.FileStream (Soursefilepath, Fi Lemode.open, FileAccess.Read, Fileshare.readwrite)) {AspoSe.                    Cells.workbook Workbook = new Workbook (stream);                    Pdfsaveoptions pdfsaveoptions = new Pdfsaveoptions ();                    Pdfsaveoptions.compliance = pdfcompliance.pdfa1b; Workbook.                    Save (Outpdfpath, ASPOSE.CELLS.SAVEFORMAT.PDF);                return true;            }} catch (Exception ex) {return false; }        }    }

Then convert the converted PDF file to SWF format, where I'm using Swftool. Inside of the Pdf2swf.exe, this is also a different function of mutual conversion, but I only use this exe here.

     public static bool Getswffrompdf (string Pdfpath, String swfpath) {try {                String exepath = HttpContext.Current.Server.MapPath ("~/exe/pdf2swf.exe");                StringBuilder sb = new StringBuilder (); Sb. Append ("\" "+ Pdfpath +" \ "");//input position sb. Append ("-T 9");//flash version sb. Append ("-o" + "\" "+ Swfpath +" \ "");//output location SB. Append ("-j 100");//Generate Flash quality if (!                File.exists (ExePath)) {//exe program does not exist return false; } else {//splicing cmd command line string command = "cmd.exe/c" + P Ath. GetFileName (ExePath) + "" + sb.                    ToString (); using (Process process = new process ()) {ProcessStartInfo startinfo = new Proce                        Ssstartinfo (); StartInfo.                   FileName = "cmd.exe";     StartInfo.                        Arguments = command; StartInfo.                        WorkingDirectory = Path.getdirectoryname (ExePath); Process.                        StartInfo = StartInfo; Process.                        Start (); Process.                        WaitForExit ();                            if (File.exists (HttpContext.Current.Server.MapPath (Swfpath)))//indicates successful write {                        return true;                        } else {return false;            }}}} catch (Exception ex)            {return false; }        }

Here is the first splicing the conversion command and then use the CMD call Pdf2swf.exe to convert.

Finally, use Flexpaper to display the generated SWF file on the page. Download the JS file to Flexpaper's official website. Put <script src= "~/scripts/js/flexpaper.js" ></script><link href= "~/scripts/css/flexpaper.css" in your page rel= "stylesheet"/> The two introduced. The address of the swffile is the address of the SWF file generated above.

    <div id= "DocumentViewer" class= "Flexpaper_viewer" style= "position:relative;width:80%;height:98%" ></div > <script type= "Text/javascript" > $ ("#documentViewer"). Flexpaperviewer ({config: {swffile: @Vi                                Ewbag.url, scale:0.6, zoomtransition: ' EaseOut ', zoomtime:0.5, zoominterval:0.2, FITPA Geonload:true, Fitwidthonload:false, Fullscreenasmaxwindow                                : false, Progressiveloading:false, minzoomsize:0.2,                                Maxzoomsize:5, Searchmatchall:false, Toolbar:toolbardata,//bottoMtoolbar: ' ui_flexpaper_annotations.html ', Initviewmode: ' Portrait ', Renderingorder: ' Flash ', startatpage: ', Viewmodet Oolsvisible:true, Zoomtoolsvisible:true, navtoolsvisible:                                True, Cursortoolsvisible:true, Searchtoolsvisible:true,                            WMode: ' Window ', Localechain: ' en_US '    }                        }                                        ); </script>

2 Do not convert PDF files to Swf,aspose+pdfobject.js

Pdfobject.js is a plugin for displaying PDF files in a Web page, very simple and easy to use.

First download the file on the official website https://pdfobject.com/the JS file to your page.

@{    viewbag.title = "Index";} 

  

And then it's ready.

3 Aspose+pdf.js

Several implementation methods of online document preview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.