A lightweight JavaScript utility for dynamically embedding PDFs in HTML documents
npm install pdfobject    
A lightweight JavaScript utility for dynamically embedding PDFs in HTML documents.
Examples and documentation can be found at https://pdfobject.com.
A PDFObject component for Vue.js 3 can be found at https://github.com/pipwerks/pdfobject-vue/
Copyright (c) 2008-2025 Philip Hutchison
MIT-style license: http://pipwerks.mit-license.org/
-----
fallbackFileNameForBase64 option. If the browser doesn't support PDF embeds, and the PDF is a base64 file, this option will enable the developer to specify the filename for the downloaded PDF. Previously, the filename was hardcoded to 'file.pdf'. Thanks to Joshua Newall (@imjosh) for the contribution. in favor of . PDFObject had previously defaulted to an element, but over time it has become apparent the superior solution is . It's universally supported, and does not suffer from 's odd quirks and spotty support. This should make PDFObject more consistent and robust across platforms. and redefining the detection logic, some PDFObject options have become obsolete. They are safe to keep in your code (will not throw errors), but are no longer used by PDFObject. The deprecated options are: assumptionMode, forceIframe, and supportRedirect.navigator.pdfViewerEnabled, per #290. As of Spring 2023, navigator.pdfViewerEnabled is supported in all major browsers. This naturally led to redefining PDFObject's PDF support detection logic. navigator.pdfViewerEnabled. navigator.pdfViewerEnabled is found and set to true, PDFObject will embed the PDF. navigator.pdfViewerEnabled is not found, fallback logic will kick in and check what kind of browser is being used. page is always set if comment, viewrect or highlight are specified.pdfOpenParams handling, resolves issue #272. Hat tip to Theo Beers.embed and iframe elements, per #274fallbackLink handling to ensure false is respected. Hat tip to Theo Beers.title attribute to PDFJS iframe elements per #258title attribute to embed and iframe elements per #248assumptionMode is enabled. However assumptionMode will still be available for browsers that are not declared modern.allow="fullscreen" attribute to iframe embeds, in case anyone needs their PDFs to be rendered fullscreen.typeof check for window to play nice with React and NextJS.suppressConsole functionality. Hat tip to John Hunter for the discovery and fix.omitInlineStyles to true. This helps developers who use strict environments where inline styles are not allowed. Note you will be responsible for applying proper styling via your own CSS.suppressConsole to true. PDFObject currently places error messages in the console if the PDF can't be embedded for some reason. This option allows you to mute those alerts.) by setting forceIframe to true.let in lieu of var, el.classList.add() in place of el.className = 'foo', and myvar === undefined in place of typeof myvar === "undefined". Implemented a let declaration before each variable instead of the Crockford practice of one var per function. element. Setting supportRedirect to true forces PDFObject to use an instead of an for desktop Safari. Hat tip to John Hunter for the discovery and fix.innerHTML. Replaced with standard DOM methods. This helps alleviate unforeseen issues with file names. Only exception is insertion of fallback content, which is passed as a string via innerHTML.assumptionMode default from false to true. This will ensure PDFObject 2.x will work for Firefox users without requiring them to change their codebase to enable assumptionMode. All they need to do is load the latest version of PDFObject, the PDFObject utility will take care of the rest.navigator.mimeTypes inspection. Added assumptionMode for manual override of PDFObject's default navigator.mimeTypes sniffing.