ASP. NET implements the browse for PDF, SWF and other documents

Source: Internet
Author: User

One, the PDF browse

With the help of the Pdf.js plugin, the advantage of using pdf.js is that there is no need to install additional plugins (such as Flash), which is a pure web-based solution. Download link for plugin: http://mozilla.github.io/pdf.js/.

As you can see from the sample code inside the Pdf.js, actually browsing the PDF document is implemented through viewer.html. Follow the link by passing in the file parameter to enable browsing of different documents. For example, the following links:

  <a href= "#" onclick= "Show ('.. /.. /js/pdf.js/web/viewer.html?file=/damis/pdffiles/{sfzh}.pdf ') ">pdf</a>

Where the show method is my definition of a JS method, for the popup window, defined as follows:

<script type= "Text/javascript" >    function Show (OPENURL) {        var iwidth = 820;//width of popup window;        var iheight = 680; The height of the popup window;        var iTop = (window.screen.availheight-30-iheight)/2; Get the vertical position of the window;        var ileft = (window.screen.availwidth-10-iwidth)/2; Get the horizontal position of the window;        window.open (OpenUrl, "", "height=" + iheight + ", width=" + iwidth + ", top=" + ITop + ", left=" + ILeft + ", Toolbar=no,me Nubar=no,scrollbars=no,resizable=no,location=no,status=no,alwaysraised=yes,depended=yes ");    } </script>

{Sfzh} is the way in which parameters are passed inside the ext.net, not the focus.

Second, the SWF browse

Sometimes in order to pursue a better browsing experience, you may need to use flash. There are ready-made flexpaper to use.

Flexpaper only receives SWF files, all of which must be ready before use. Since we have generated PDF documents as above through ITEXTSHARP, we just need to convert the PDF to SWF. This function we can use Pdf2swf.exe to complete, can go to http://www.swftools.org/download.

The

Implementation of the PDF-to-SWF conversion code is as follows:

protected void Page_Load (object sender, EventArgs e) {if (!        X.isajaxrequest) {String sfzh = request.querystring["Sfzh"] as String;        string exe = Server.MapPath ("~/base/pdf2swf.exe");        String Source = Commonutil.getlocalpathbyidentitycard (Sfzh) + Sfzh + ". pdf";        String dest = Path.Combine (Server.MapPath ("~"), "swf\\" + Sfzh + ". Swf"); if (!            File.exists (dest)) {System.Diagnostics.Process Process = new System.Diagnostics.Process (); Process.            Startinfo.filename = EXE; Process.            startinfo.arguments = Source + "-o" + dest + "-t 9-f"; Process.            Startinfo.windowstyle = System.Diagnostics.ProcessWindowStyle.Hidden; Process.            Startinfo.createnowindow = true; Process.            Startinfo.useshellexecute = false; Process.            Startinfo.redirectstandardinput = true; Process.            Startinfo.redirectstandardoutput = true; Process.            Startinfo.redirectstandarderror = true; ProcEss.            Start (); Process.            WaitForExit (); Process.        Close (); } string swffile = "... /..        /swf/"+ Sfzh +". SWF "; This.    Literal1.text = "var swffile = '" + swffile + "'"; }}

This is achieved through the process processes.

Front Code:

<a href= "#" onclick= "Show (' Daswfview.aspx?sfzh={sfzh} ')" >swf</a>

The Show method is the same as the JS method for the PDF pop-up document.

The HTML code in the popup daswfview.aspx page is as follows:

<%@ page language= "C #" autoeventwireup= "true" codebehind= "DASwfView.aspx.cs" inherits= "Damis. Web.Web.DAQueryStatistics.DASwfView "%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

As on the need to reference a few JS files can be downloaded to. Documentview.js There is a piece of code in this file that needs attention:

swfobject.embedSWF (                ".. /.. /swf/documentviewer.swf "," Flashcontent ",                " $ "," 675 "," 10.0.0 "," playerproductinstall.swf ",                flashvars, params, attributes);

The documentviewer.swf file here borrows the Insus insusdocumentviewer.swf file (changed name). And this part of the implementation is also reference to the Insus solution, specific can refer to: http://www.cnblogs.com/insus/p/3574298.html this blog post.

The following code implements the ability to convert PDFs to SWF online and display them as follows:

ASP. NET implements the browse for PDF, SWF and other documents

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.