Go PDF Preview Plugin Pdfobject.js

Source: Internet
Author: User
Tags pdfobject

This article transferred from: http://pdfobject.com/index.php

When possible, use standardized HTML markup and avoid JavaScript

In a ideal world, would embed your PDF files using a <object> element hard-coded in your HTML Marku P. Why? For starters, avoiding JavaScript usually means greater accessibility, greater searchability (important for those concerne D with search engine optimization), and fewer browser compatibility issues. Since no JavaScript is being used, standardized markup are also quicker to load and less of a drain on computer and network Resources.

Click here to learn more about embedding PDFs using standardized HTML markup.

Sometimes you need a little JavaScript. When you do, try Pdfobject.

Some projects would require dynamically embedded PDFs. pdfobject is designed for this purpose, and makes Embeddin G PDFs quick and easy while maintaining a healthy respect for standards.

Pdfobject uses JavaScript to generate the same standards-compliant <object> markup you would normally write Rself, then inserts the <object> into your HTML element of choice. You can fill the entire browser window, or insert the PDF to a <div> or other block-level element.

Here's a very simple no-frills example of pdfobject; This example would make the PDF fill the entire browser window:

pdfobject.js "></script><script type=" Text/javascript ">      window.onload = function () {        var success = new Pdfobject ({URL: "Sample.pdf"}). Embed ();      };     </script>   

Embedding a PDF can ' t get much easier! There is also many other embed options available; Visit the code generator to see what ' s possible.

    • Click here to read detailed instructions for using Pdfobject.
    • Click here to see examples of pdfobject in action.
Features
  • Detection of PDF plugin or PDF file-handling support.
    • Checks for Adobe Reader.
    • Checks for generic support via the application/pdf MIME type.
  • Only attempts to embed PDF if detected.
    • If PDF support is detected, the <object> are embedded with all specified parameters;
    • If PDF support was not found, the <object> would not being embedded, and the fallback content is Le FT As-is.
  • Returns reference to the HTML <object> (similar to getElementById) or null.
  • If no element ID is passed into the embed () call, Pdfobject would default to Document.body, filling the entire brow Ser window.
  • Accepts optional embed parameters, including size, ID, and most PDF open parameters.
  • Automatically appends extra CSS needed for Full-window PDF embeds
    • Removes padding and margins
    • Fixes 100% height issue in some browsers

Compatibility

Please note this compatibility chart have not been updated to reflect Pdfobject 1.2.

Pdfobject is compatible with every major browser capable of displaying PDFs. Please note these results is from internal testing of pdfobject using Adobe Reader; No Open-source PDF browser plugins were used during testing.

TD class= "NA" >not applicable
Windows XP (Professional) Windows Vista (business) Mac OS X 10.5 (Le Opard) Ubuntu 8.04 (Hardy Heron)
internet Explorer 6 x not applicable not applicable
internet Explorer 7< /th> x x not applicable not applicabl E
mozilla Firefox 3 x x no Adobe Reader plugin x
apple Safari 3.1 x x x not applicable
opera 9.5 x x no Adobe Reader plugin x

Not applicable: Specified browser are not produced for this operating system. no Adobe Reader plugin: Adobe Reader unavailable for this browser/os combination.

Syntax

Pdfobject ' s syntax would feel very familiar to users of JavaScript frameworks such as JQuery and MooTools. Here's a typical example:

var mypdf = new Pdfobject ({  URL: "Sample.pdf",  ID: "Mypdf",  width: "500px",  Height: "300px",  Pdfopenparams: {    navpanes:1,    statusbar:0,    view: "Fith",    pagemode: "Thumbs"  }}). Embed ("Mydiv ");

Here ' s another example:

var myparams = {   URL: "Sample.pdf",  pdfopenparams: {view: "Fitv"}};var mypdf = new Pdfobject (myparams). Embed (" Mydiv "); Returns reference to new HTML <object>

Note that embed was chained on to the new Pdfobject statement. You can also use them separately:

var myparams = {   URL: "Sample.pdf",  pdfopenparams: {view: "Fitv"}};var mypdf = new Pdfobject (myparams);  Returns reference to JavaScript objectmypdf.embed ("mydiv");  Returns reference to new HTML <object>

Properties and methods

Pdfobject contains the following properties and methods.

Name Type Description
Pdfobject (obj) Constructor

Use a object for passing arguments. obj can contain the following arguments:

  • URL (string, required)
  • ID (String)
  • Width (string, with unit of measurement such as "100%" or "500px")
  • Height (string, with unit of measurement such as "100%" or "500px")
  • Pdfopenparams (object, may contain any of the PDF Open properties specified by Adobe)

Returns reference to self (this).

Pdfobject.embed (Targetid) Method Embeds PDF. Returns HTML <object> element or False if embed not successful.
Pdfobject.get (prop) Method

Returns value of property. Found or has no value, returns null. Available Properties:

  • URL (String)
  • ID (String)
  • Width (string)
  • Height (string)
  • Pdfopenparams (object)
  • Plugintypefound (String)
  • Pdfobjectversion (String)
Pipwerks.pdfUTILS.detect.hasReader () Support function Returns Boolean indicating whether navigator.plugins version of Adobe Reader has been found.
Pipwerks.pdfUTILS.detect.hasReaderActiveX () Support function Returns Boolean indicating whether ActiveX version of Adobe Reader has been found.
Pipwerks.pdfUTILS.detect.hasGeneric () Support function Returns Boolean indicating whether application/pdf MIME type is supported via navigator.mimetypes
Pipwerks.pdfUTILS.detect.pluginFound () Support function Returns string "Adobe" or "generic". Returns null if none found.
PIPWERKS.PDFUTILS.SETCSSFORFULLWINDOWPDF () Support function Sets the following style properties:
Html.style.height = "100%"; Html.style.overflow = "hidden"; Body.style.margin = 0; body.style.padding = 0; Body.style.height = "100%"; Body.style.overflow = "hidden";
These properties need to is set in order to remove margins/padding in the document, and to enable the object to stretch to 100% vertically.
Pipwerks.pdfUTILS.buildQueryString (Pdfopenparams) Support function Takes properties of Pdfopenparams object and ' stringifies ' them.
Pipwerks.pdfUTILS.termFound (Strtosearch, term) Support function Returns Boolean shortcut for strtosearch.indexof ("term")!==-1
Known Issues

Pdfobject have no known issues at this time. The biggest issue are browser support for Adobe reader and/or funky behavior in reader. This was beyond the scope of this simple embed script. Shortcomings encountered with Reader during testing included:

    • Crashes/hanging when trying to replace an embedded PDF with a second PDF (by replacing the first <object> elemen T with a new <object>).
    • Crashes/hanging when attempting to embed more than one PDF in a single HTML page (FYI This behavior can is avoided by usin G IFRAMEs).
Important Note:pdfobject does not include version detection

Pdfobject does not allow you to target a specific version of Adobe Reader, such as version 7 and higher. While version detection are possible, it is a very cumbersome tasks and nearly impossible to maintain or make futur E-proof, largely due to Adobe frequently changing the plugin ' s name and description. For instance, in Safari, Adobe Reader 8.1 's name is reported as "Adobe Acrobat and Reader plug-in," while the name in the Windows version of Firefox is "Adobe PDF plug-in for Firefox and Netscape." Until version reporting is consistent in Adobe Reader (across browsers and operating systems), Pdfobject would not include Version detection.

Tip of the CAP

Pdfobject was built using information, code, tools, or inspiration provided by others, including (in no particular order):

    • SWFObject (Geoff Stearns and Bobby van der Sluis)
    • Douglas Crockford ' s JSLint
    • The JavaScript Compressor
    • Documentation provided by Adobe at Adobe.com
    • Detecting plugins in Internet Explorer (and a few hints for all the others)
    • Http://www.howtocreate.co.uk/wrongWithIE/?chapter=navigator.plugins (Mark wilton-jones)
    • Determining Adobe Acrobat PDF Reader Plugin support Using JavaScript

Thanks, guys!

Go PDF Preview Plugin Pdfobject.js

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.