PDF online preview, compatible with IE and chrome. Pdfobject. js and chromepdfobject. js are used.

Source: Internet
Author: User
Tags pdfobject

PDF online preview, compatible with IE and chrome. Pdfobject. js and chromepdfobject. js are used.

PDF online preview, compatible with IE and CHROME

Http://files.cnblogs.com/w519/PDFViewSolution.rar

My PDF Online Preview DEMO uses pdfobject. js and adobe Reader.

Because PDFobjcet. js is not compatible with IE, pdfobjcet. js is used to open PDF in chrome, while adobe Reader is used to open PDF in IE.

Problem: expiration and other end extensions, which are downloaded by default and cannot be redirected to the page.

Method: you can remove the file extension in the url without downloading it!

1. Check the browser on the Default. aspx page. If it is IE and whether adobe Reader is installed, go to the preview view. aspx page and output a PDF file in the background. If chrome is used, use pdfobject. js to output a PDF file on this page.

Default. aspx code

<Script src = "Scripts/jquery-1.4.1.min.js" type = "text/javascript"> </script> <script src = "Scripts/pdfobject. js "type =" text/javascript "> </script> <script type =" text/javascript ">$ (function () {var w = $ (document ). width (); var h = $ (document ). height (); $ ("# pdf1" ).css ("width", w).css ("height", h); // the following code processes IE browser conditions if (window. activeXObject | "ActiveXObject" in window) {// determines whether it is an IE browser, "ActiveXObject" In window determines whether it is IE11 // determines whether adobe Reader for (x = 2; x <10; x ++) is installed) {try {oAcro = eval ("new ActiveXObject ('pdf. CTRL. "+ x +" '); "); if (oAcro) {flag = true ;}} catch (e) {flag = false ;}} try {oAcro4 = new ActiveXObject ('pdf. export ctrl.1 '); if (o1_4) {flag = true ;}} catch (e) {flag = false ;}try {o1_7 = new ActiveXObject ('your PDF. when .1 '); if (o1_7) {flag = true ;}} catch (e) {f Lag = false;} if (flag) {$ ('# pdf1 '). hide (); location = "lateral view. aspx ";} else {alert (" Sorry, you have not installed the PDF Reader software yet. For the convenience of previewing the PDF document, please choose to install it! "); Location =" http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.3/chs/AdbeRdr930_zh_CN.exe ";}} Else {// alert ($. trim (urls); var success = new PDFObject ({url: 'pdf/19-p1037928-064_zhcn-draftyun', export openparams: {scrollbars: '0', toolbar: '0', statusbar: '0 '}}). embed ("pdf1"); if (! Success) {var opts = {width: $ (document ). width (), height: $ (document ). height (), autoplay: true };}}}); </script> Lateral view. aspx. cs code

Protected void Page_Load (object sender, EventArgs e) {if (Request. Browser. Browser. ToLower ()! = "Chrome") {string filePath = Server. mapPath ("pdf/19-p1038528-064_zhcn-draft.pdf"); Response. clearContent (); Response. clearHeaders (); string FilePost = filePath. substring (filePath. length-3 ). toLower (); switch (FilePost) {case "pdf": Response. contentType = "application/PDF"; break; case "doc": Response. contentType = "application/msword"; break; case "xls": Response. contentType = "application/vnd. ms-excel "; break; default: Session [" ErrorInfo "] =" unsupported File Format: "+ FilePost; Response. redirect ("ErrorPage. aspx "); break;} Response. writeFile (filePath); Response. flush (); Response. close (); Session. remove ("Report");} else if (Request. browser. browser. toLower () = "chrome") {string filePath = Server. mapPath ("pdf/19-p1038528-064_zhcn-draft.pdf"); Response. clearContent (); Response. clearHeaders (); string FilePost = filePath. substring (filePath. length-3 ). toLower (); Response. clear (); Response. clearHeaders (); Response. buffer = false; if (Request. browser. browser = "Firefox") System. web. httpContext. current. response. appendHeader ("Content-Disposition", "attachment; filename =" + "1.20."); else System. web. httpContext. current. response. appendHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. urlEncode ("1.20.", System. text. encoding. UTF8); using (System. IO. fileStream fs = new System. IO. fileStream (filePath, System. IO. fileMode. open) {byte [] by = new byte [fs. length]; fs. read (by, 0,. length); Response. binaryWrite (by); Response. addHeader ("Accept-Language", "zh-tw"); Response. contentType = "application/octet-stream"; Response. appendHeader ("Content-Length",. length. toString (); System. web. httpContext. current. response. flush (); System. web. httpContext. current. response. end ();}}}

 

 

 

 

Related Article

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.