pdfjs-serverless 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,6 @@
1
1
  # pdfjs-serverless
2
2
 
3
- A nodeless/serverless redistribution of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js) for serverless enviroments, like Deno Deploy and Cloudflare Workers with zero dependencies.
4
-
5
- ## How It Works
6
-
7
- First, some string replacements of the `pdf.js` library is necessary, i.e. removing browser context references. Additionally, we enforce Node.js (might sound paradox at first, bear with me) compatibility, i.e. mocking the `canvas` module and setting the `isNodeJS` flag to `true`.
8
-
9
- To achieve a nodeless build, [`unenv`](https://github.com/unjs/unenv) does the heavy lifting by converting Node.js specific code to be platform-agnostic.
10
-
11
- See the [`rollup.config.js`](./rollup.config.js) file for more information.
3
+ A redistribution of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js) for serverless environments, like Deno Deploy and Cloudflare Workers with zero dependencies. All named exports of the `PDF.js` library are available at roughly 1.4 MB (minified).
12
4
 
13
5
  ## Installation
14
6
 
@@ -25,14 +17,24 @@ npm install pdfjs-serverless
25
17
  yarn add pdfjs-serverless
26
18
  ```
27
19
 
20
+ ## How It Works
21
+
22
+ First, some string replacements of the `PDF.js` library is necessary, i.e. removing browser context references and checks like `typeof window`. Additionally, we enforce Node.js compatibility (might sound paradox at first, bear with me), i.e. mocking the `canvas` module and setting the `isNodeJS` flag to `true`.
23
+
24
+ PDF.js uses a worker to parse and work with PDF documents. This worker is a separate file that is loaded by the main library. For the serverless build, we need to inline the worker code into the main library.
25
+
26
+ To achieve the final nodeless build, [`unenv`](https://github.com/unjs/unenv) does the heavy lifting by converting Node.js specific code to be platform-agnostic. This ensures that Node.js built-in modules like `fs` are mocked.
27
+
28
+ See the [`rollup.config.ts`](./rollup.config.ts) file for more information.
29
+
28
30
  ## Example Usage
29
31
 
30
- ### Deno
32
+ ### 🦕 Deno
31
33
 
32
34
  ```ts
33
35
  import { getDocument } from 'https://esm.sh/pdfjs-serverless'
34
36
 
35
- const data = Deno.readFileSync('./dummy.pdf')
37
+ const data = Deno.readFileSync('dummy.pdf')
36
38
  const doc = await getDocument(data).promise
37
39
 
38
40
  console.log(await doc.getMetadata())
@@ -45,30 +47,6 @@ for (let i = 1; i <= doc.numPages; i++) {
45
47
  }
46
48
  ```
47
49
 
48
- ### In Combination With `unpdf`
49
-
50
- The following example shows how to use `pdfjs-serverless` with [`unpdf`](https://github.com/johannschopplich/unpdf):
51
-
52
- ```ts
53
- import { defineUnPDFConfig, extractPDFText } from 'unpdf'
54
-
55
- // Use the serverless version of PDF.js
56
- defineUnPDFConfig({
57
- pdfjs: () => import('pdfjs-serverless')
58
- })
59
-
60
- // Now, you can use the other methods provided by unpdf
61
-
62
- // Fetch a PDF file from the web
63
- const pdf = await fetch('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf')
64
- .then(res => res.arrayBuffer())
65
-
66
- // Pass the PDF buffer to the relevant method
67
- const { totalPages, text } = await extractPDFText(
68
- new Uint8Array(pdf), { mergePages: true }
69
- )
70
- ```
71
-
72
50
  ## Inspiration
73
51
 
74
52
  - [`pdf.mjs`](https://github.com/bru02/pdf.mjs), a nodeless build of PDF.js v2.
@@ -0,0 +1 @@
1
+ export * from './types/src/pdf.d.ts'