2.0.946 • Published 5 years ago

@dks9556/pdfjs-dist v2.0.946

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
5 years ago

pdfjs-dist

This is a mirror of pdfjs-dist, bundled and exposed as an ES module

Install

npm install @bundled-es-modules/pdfjs-dist

Use

import pdfjs from "@bundled-es-modules/pdfjs-dist/build/pdf";
import viewer from "@bundled-es-modules/pdfjs-dist/web/pdf_viewer";

pdfjs.GlobalWorkerOptions.workerSrc =
  "@bundled-es-modules/pdfjs-dist/pdf.worker.js";

var url = "basicapi.pdf";
var loadingTask = pdfjs.getDocument(url);
//...

Important: Unlike in the original build, the pdfjs.GlobalWorkerOptions.workerSrc is mandatory.

Overview

Structure

├── build/
│   ├── pdf.js                    - display layer
│   └── pdf.worker.js             - core layer
└── web/
    ├── pdf_viewer.js             - top-level viewer import, containing all necessary setup
    ├── module.js                 - pdf-viewer module, transformed from UMD to ESM
    └── util.js                   - utility module for setup

Background

PDFJS is a library by Mozilla, created to facillitate client-side rendering of PDF documents.

Currently, the primary build for this project is provided as UMD-style modules at pdfjs/pdfjs-dist.

Support for es modules in the main project has been requested here (#10317)

Rollup configuration

pdf.js
  • Transform UMD to ESM
  • Resolve commonJS imports, except:
  • Ignore pdf.worker.js import. This is very important, as it's conditionally required and is very large in size.
  • Copy over all remaining files we wish to provide.

With pdf.worker.js ignored, pdfjs will expect a link to the file externally (see above)

pdf_viewer.js
  • Transform UMD to ESM
  • Resolve imports
  • Ignore pdf.js. This is important, as we don't want to serve duplicates of pdfjs.

With pdf.js ignored, the viewer will expect to find a global pdfjs. This is circumvented by temporarily adding pdfjs to the global scope, and removed immediately after the viewer acquires a reference.

Building

npm run build
2.0.946

5 years ago

2.0.945

5 years ago

2.0.944

5 years ago

2.0.943

5 years ago