You have to set GlobalWorkerOptions.workerSrc to /build/pdf.worker(.min).js of same version:
pdfjsLib.GlobalWorkerOptions.workerSrc =
"https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.worker.min.js";
pdfjsLib.getDocument('./ahmed.pdf').promise.then(doc => {
console.log(`This document has ${doc._pdfInfo.numPages} pages.");
});
And, as @Pasi has mentioned, you have to promisify .getDocument() by chaining .promise on it. Without it, there is no .then().
Top answer 1 of 3
4
You have to set GlobalWorkerOptions.workerSrc to /build/pdf.worker(.min).js of same version:
pdfjsLib.GlobalWorkerOptions.workerSrc =
"https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.worker.min.js";
pdfjsLib.getDocument('./ahmed.pdf').promise.then(doc => {
console.log(`This document has ${doc._pdfInfo.numPages} pages.");
});
And, as @Pasi has mentioned, you have to promisify .getDocument() by chaining .promise on it. Without it, there is no .then().
2 of 3
1
See the "Hello World with document load error handling" example on this page to get started: https://mozilla.github.io/pdf.js/examples/
(Your snippet is missing .promise after getDocument() and setting the workerSrc property)
jsDelivr
jsdelivr.com › package › npm › pdfjs-dist
pdfjs-dist CDN by jsDelivr - A CDN for npm and GitHub
September 22, 2014 - A free, fast, and reliable CDN for pdfjs-dist. Generic build of Mozilla's PDF.js library.
Published Sep 22, 2014
Repository https://github.com/mozilla/pdf.js
Videos
cdnjs
cdnjs.com › home › libraries › pdf.js › 2.6.347
pdf.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers
Some files are hidden, click to show all files · https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.js · https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.js.map ·
GitHub
github.com › mozilla › pdf.js › discussions › 17642
Using CDN links in "demo" `web/viewer.html` · mozilla/pdf.js · Discussion #17642
<link rel="resource" type="application/l10n" href="locale/locale.json"> <script src="../build/pdf.mjs" type="module"></script> <link rel="stylesheet" href="viewer.css"> <script src="viewer.mjs" type="module"></script> I have already verified that if I change the reference of "../build/pdf.mjs" to: <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.mjs" type="module"></script>
Author mozilla
Mozilla
mozilla.github.io › pdf.js › getting_started
PDF.js - Getting Started
$ git clone https://github.com/mozilla/pdf.js.git $ cd pdf.js
GitHub
github.com › mozilla › pdf.js › issues › 5490
make pdf.js available on a cdn · Issue #5490 · mozilla/pdf.js
November 17, 2014 - Having pdf.js available on a public cdn can simplify installation and update workflows in some cases. cdnjs will likely host pdf.js for free if was ask them to. cdnjs/cdnjs#3824
Published Nov 17, 2014
PDF.js Express
pdfjs.express › documentation › learn-more › cors
Loading PDF.js Express from a CDN or another origin | Documentation
// config.js window.addEventListener('viewerLoaded', () => { instance.UI.loadDocument('https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf') }) Once your config file is set up, you can upload that to your CDN as well. Now, tell WebViewer the location of the config file like so: import WebViewer from '@pdftron/pdfjs-express' WebViewer({ path: "https://my-cdn.com/pdfjs-express/public", config: "https://my-cdn.com/pdfjs-express/config.js" })
Mozilla
mozilla.github.io › pdf.js
PDF.js - Home
A general-purpose, web standards-based platform for parsing and rendering PDFs.
Javascripting
javascripting.com › view › pdf-js
Pdf.js - JavaScripting
https://cdnjs.com/libraries/pdf.js · https://unpkg.com/pdfjs-dist/ You can play with the PDF.js API directly from your browser using the live demos below: Interactive examples · More examples can be found in the examples folder. Some of them are using the pdfjs-dist package, which can be built and installed in this repo directory via npx gulp dist-install command.
Nutrient
nutrient.io › blog › sdk › implement pdf viewer pdf js
PDF.js viewer example: Implement a simple PDF viewer with PDF.js
October 17, 2024 - Whether you’re building a document management system or any other application that requires PDF functionality, PDF.js provides the foundational tools to get started. Before we dive into the viewer implementation, we’re going to lay down a minimal HTML skeleton for our application: ... This HTML file includes the basic toolbar for navigating the pages, an input for controlling page mode, and a viewport where the PDF will be rendered. We use a CDN version of pdf.min.mjs to include PDF.js.
GitHub
github.com › mozilla › pdf.js
GitHub - mozilla/pdf.js: PDF Reader in JavaScript
https://cdnjs.com/libraries/pdf.js · https://unpkg.com/pdfjs-dist/ You can play with the PDF.js API directly from your browser using the live demos below: Interactive examples · More examples can be found in the examples folder. Some of them are using the pdfjs-dist package, which can be built and installed in this repo directory via npx gulp dist-install command.
Starred by 52.4K users
Forked by 10.5K users
Languages JavaScript 71.3% | Fluent 25.5% | CSS 2.2%
Mozilla
mozilla.github.io › pdf.js › examples
PDF.js - Examples
This tutorial shows how PDF.js can be used as a library in a web browser. examples/ provides more examples, including usage in Node.js (at examples/node/).
CopyProgramming
copyprogramming.com › howto › how-to-import-pdf-js-using-cdn
Utilizing CDN for the Integration of pdf.js - Javascript
May 16, 2023 - Utilizing CDN to Incorporate pdf.js, Pdfjs-dist, Utilizing the pdf.js library to display an entire PDF document
GitHub
github.com › mozilla › pdf.js › issues › 14900
CDN-hosted legacy version of pdfjs-dist has syntax errors in IE · Issue #14900 · mozilla/pdf.js
February 28, 2022 - <!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title>PDF.js 'Hello, world!' example, legacy version</title> <style> #the-canvas { border: 1px solid black; direction: ltr; } </style> </head> <body> <h1>PDF.js 'Hello, ...
Published May 10, 2022
PDF.js Express
pdfjs.community › technical support
Is there any CDN url for PDFJS express library - Technical Support - PDF.js Express
May 30, 2021 - Hi Team, We are giving the web-viewer folder library path for rendering the pdf. In local it is working. But in our server we are getting path issue. In our angular project we are using only main.js. Do you have CDN url for the library so that we don’t want to store the lib folder in our project and our path issue will be solved.
PDF-LIB
pdf-lib.js.org
PDF-LIB · Create and modify PDF documents in any JavaScript environment.
https://cdn.jsdelivr.net/npm/[email protected]/dist/pdf-lib.min.js