由於在做手機項目中需要用到預覽pdf文件的需求,一搜還真多,試用后發現兼容性不是很好,大多需要瀏覽器對pdf閱讀的支持;
如果你只是想不依賴瀏覽器本身對pdf解析的情況下,在手機展示pdf文件,就需要了解各個插件的優缺點進行選擇;
該插件需要用到瀏覽器h5解析pdf的支持,在手機webview使用兼容性不是很好,下面看官方的說明:
Why use PDFObject?
PDFObject 2.0 detects browser support for inline/embedded PDFs. (In case you were wondering, your browser supports embedded PDFs. You lucky dog, you!)
If you're working with dynamic HTML, such as a single-page web app, you may need to insert PDFs on-the-fly. However, PDF embedding is not supported by certain browsers. If you insert markup without first checking for PDF support, you could wind up with missing content or a broken UI.
The PDFObject utility helps you avoid these situations by detecting support for PDF embedding in the browser; if embedding is supported, the PDF is embedded. If embedding is NOT supported by the browser, the PDF will NOT be embedded.
By default, PDFObject 2.0 inserts a fallback link to the PDF when the browser does not support inline PDFs. This ensures your users always have access to your PDF, and is designed to help you write less code. The fallback link can be customized, or the option can be disabled if you prefer.
PDFObject 2.0 is npm-ready. Modern web apps use npm to manage packages and dependencies. PDFObject 2.0 is registered with Node Package Manager (npm) and can be loaded dynamically.
PDFObject also makes it easy to specify Adobe's proprietary "PDF Open Parameters". (Be warned these parameters are only supported by Adobe Reader, most PDF readers will ignore the parameters, including the built-in PDF readers in Chrome, Internet Explorer, and Safari. Read more below.)
為什么要使用PDFObject?
PDFObject 2.0檢測瀏覽器支持嵌入式/嵌入式PDF。 (如果你想知道,你的瀏覽器支持嵌入式PDF,你幸運的狗,你!)
如果您正在使用動態HTML,例如單頁網絡應用程序,則可能需要即時插入PDF。但是,某些瀏覽器不支持PDF嵌入。如果您在沒有首先檢查PDF支持的情況下插入標記,則可以彌補缺少的內容或損壞的UI。
通過檢測對瀏覽器中的PDF嵌入的支持,PDFObject實用程序可以幫助您避免這些情況;如果支持嵌入,則嵌入PDF。如果瀏覽器不支持嵌入,則不會嵌入PDF。
默認情況下,當瀏覽器不支持內聯PDF時,PDFObject 2.0將插入到PDF的后備鏈接。這確保您的用戶始終可以訪問您的PDF,旨在幫助您編寫更少的代碼。后備鏈接可以自定義,或者如果您願意,可以禁用該選項。
PDFObject 2.0已經准備好了。現代網絡應用程序使用npm來管理軟件包和依賴項。 PDFObject 2.0已在Node Package Manager(npm)中注冊,可以動態加載。
PDFObject還可以輕松地指定Adobe的專有“PDF打開參數”。 (請注意,這些參數僅由Adobe Reader支持,大多數PDF閱讀器將忽略參數,包括Chrome,Internet Explorer和Safari中的內置PDF閱讀器,請閱讀下文。)
What PDFObject doesn't do
PDFObject is not a rendering engine. PDFObject just writes an <embed> element to the page, and relies on the browser or browser plugins to render the PDF. If the browser does not support embedded PDFs, PDFObject is not capable of forcing the browser to render the PDF.
If you need to force browsers to display a PDF, we suggest using Mozilla's PDF.js. Note that PDF.js is subject to its own limitations, such as cross-domain security restrictions. PDFObject and PDF.js play well together, there are links to some great PDF.js examples in the Examples section below.
PDFObject does not provide the ability to customize the look and feel of the PDF toolbar. The toolbar is controlled by the browser, and will vary widely from browser to browser (Chrome versus Safari versus Firefox, etc.). Some of these browsers provide the ability to show or hide the toolbar, or a feature such as the search field, via PDF Open Parmeters. However, in general the browsers do NOT provide any mechanism for customizing the toolbar. If you really need to customize the toolbar, try forking Mozilla's PDF.js and customizing it to suit your needs.
PDFObject does not validate the existence of the PDF, or that the PDF is actually rendered. The assumption is that you are specifying a valid URL and the network is functioning normally. PDFObject does not check for 404 errors, and JavaScript cannot detect whether the PDF actually renders, unless you are using PDF.js, which is outside the scope of PDFObject.
PDFObject does not magically implement PDF Open Parameters. As mentioned above, these parameters are not widely supported. The PDF rendering engine either supports them or doesn't — PDFObject cannot force the rendering engine to implement these features.
什么PDFObject不做
PDFObject不是一個渲染引擎。 PDFObject只是將一個<embed>元素寫入頁面,並依賴於瀏覽器或瀏覽器插件來呈現PDF。如果瀏覽器不支持嵌入式PDF,PDFObject不能強制瀏覽器呈現PDF。
如果您需要強制瀏覽器顯示PDF,我們建議使用Mozilla的PDF.js.請注意,PDF.js有其自身的限制,如跨域安全限制。 PDFObject和PDF.js很好地協同工作,下面的例子中有一些很棒的PDF.js示例鏈接。
PDFObject不提供自定義PDF工具欄的外觀的功能。工具欄由瀏覽器控制,並且從瀏覽器到瀏覽器(Chrome與Safari和Firefox等)的差異很大。其中一些瀏覽器提供了通過PDF打開Parmeters顯示或隱藏工具欄或功能(如搜索字段)的功能。但是,一般來說,瀏覽器不提供自定義工具欄的任何機制。如果您真的需要自定義工具欄,請嘗試針對Mozilla的PDF.js進行自定義以滿足您的需求。
PDFObject不驗證PDF的存在,或PDF實際呈現。假設您指定一個有效的URL,並且網絡正常運行。 PDFObject不檢查404錯誤,JavaScript無法檢測PDF是否實際呈現,除非您使用的PDF.js不屬於PDFObject范圍。
PDFObject不會神奇地實現PDF打開參數。如上所述,這些參數不被廣泛支持。 PDF渲染引擎支持它們或不支持 - PDFObject不能強制渲染引擎實現這些功能。
The jQuery Media Plugin supports unobtrusive conversion of standard markup into rich media content. It can be used to embed virtually any media type, including Flash, Quicktime, Windows Media Player, Real Player, MP3, Silverlight, PDF and more, into a web page. The plugin converts an element (usually an <a>) into a <div> which holds the object, embed or iframe tags neccessary to render the media content.
jQuery Media插件支持將標准標記轉換為富媒體內容。 它可以用於將幾乎任何媒體類型(包括Flash,Quicktime,Windows Media Player,Real Player,MP3,Silverlight,PDF等)嵌入到網頁中。 該插件將一個元素(通常是<a>)轉換成一個保存對象的<div>,需要嵌入或iframe標簽才能呈現媒體內容。
3、pdf.js
重點介紹的就是這個插件,可以完全脫離瀏覽器的依賴,支持pdf閱讀展示,真的很強大,這個才是我需要找的,且看插件說明:
- PDF.js是使用HTML5構建的便攜式文檔格式(PDF)查看器。
- PDF.js是由Mozilla實驗室的社區驅動和支持。 我們的目標是創建一個通用的基於Web標准的平台,用於解析和渲染PDF。
不同之處在於pdf.js是web渲染pdf引擎。
