{"library":"pdfobject","title":"PDFObject: PDF Embedding Utility","description":"PDFObject is a lightweight JavaScript utility designed for embedding PDF documents directly into HTML pages. Currently at version 2.3.1, it provides a robust solution for displaying PDFs inline across various browsers. The project maintains a steady release cadence, with significant updates (like 2.3) introducing major architectural changes approximately annually, alongside minor patches for fixes and enhancements. A key differentiator is its shift to a pure `<iframe>` approach in v2.3, abandoning the less consistent `<embed>` element, which enhances cross-browser compatibility and reliability. It also intelligently leverages `navigator.pdfViewerEnabled` to determine native PDF viewing capabilities and automatically falls back to download options on unsupported platforms, especially mobile devices. This makes it a pragmatic choice for integrating PDF content without external plugins.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pdfobject"],"cli":null},"imports":["import PDFObject from 'pdfobject'","PDFObject.embed(url, targetElement, options)","if (PDFObject.supportsPDFs) { /* ... */ }"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>PDFObject Quickstart</title>\n    <style>\n        #pdf-container {\n            width: 800px;\n            height: 600px;\n            border: 1px solid #ccc;\n            margin: 20px auto;\n        }\n    </style>\n</head>\n<body>\n    <h1>Embedding a PDF with PDFObject</h1>\n    <div id=\"pdf-container\"></div>\n\n    <!-- Load PDFObject from a CDN -->\n    <script src=\"https://unpkg.com/pdfobject/pdfobject.min.js\"></script>\n    <script>\n        // Replace with your actual PDF URL\n        const pdfUrl = 'https://pdfobject.com/pdf/sample.pdf'; \n\n        // Check if PDFObject is available and embedding is supported\n        if(PDFObject.supportsPDFs) {\n            PDFObject.embed(pdfUrl, \"#pdf-container\", {\n                height: \"100%\", // Make it fill the container\n                width: \"100%\",\n                id: \"my-embedded-pdf\",\n                // Example PDF Open Parameters (e.g., open to page 2, fit view)\n                pdfOpenParams: {\n                    view: \"FitV\",\n                    page: \"2\"\n                },\n                // Fallback content for browsers that don't support inline PDFs\n                fallbackLink: `<p>This browser does not support inline PDFs. You can <a href=\"${pdfUrl}\">download the PDF</a> instead.</p>`\n            });\n            console.log(\"PDF embedded successfully!\");\n        } else {\n            // Display fallback content if embedding is not supported\n            document.getElementById(\"pdf-container\").innerHTML = `<p>Your browser does not support inline PDFs. You can <a href=\"${pdfUrl}\">download the PDF</a> instead.</p>`;\n            console.warn(\"PDF embedding not supported in this browser.\");\n        }\n    </script>\n</body>\n</html>","lang":"javascript","description":"Demonstrates how to embed a PDF directly into an HTML element using PDFObject's `embed` method, including feature detection and fallback content.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}