You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add browser-specific entry and update worker config
Introduces src/index.browser.ts as a browser-specific entry point, sets up the correct PDF.js worker for browser builds, and updates Vite configs to use this entry. Documentation is improved for browser usage and worker configuration, and TypeScript configs now exclude the new browser entry from Node/TS builds. Also switches to the minified PDF.js worker in the worker index.
Copy file name to clipboardExpand all lines: README.md
+10-18Lines changed: 10 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -268,7 +268,8 @@ export default nextConfig;
268
268
Custom builds, Electron/NW.js, or specific deployment environments—you may need to manually configure the worker source.
269
269
270
270
```js
271
-
import {getWorkerPath, getWorkerSource} from "pdf-parse/worker"; // Import this before importing "pdf-parse"
271
+
// Import this before importing "pdf-parse"
272
+
import {getWorkerPath, getWorkerSource} from "pdf-parse/worker";
272
273
import {PDFParse} from "pdf-parse";
273
274
274
275
// CommonJS
@@ -306,7 +307,10 @@ try {
306
307
```html
307
308
<!-- ES Module -->
308
309
<script type="module">
309
-
import { PDFParse } from 'https://cdn.jsdelivr.net/npm/pdf-parse@latest/dist/browser/pdf-parse.es.min.js';
310
+
import {PDFParse} from 'https://cdn.jsdelivr.net/npm/pdf-parse@latest/+esm';
311
+
const parser = new PDFParse({url:'https://mehmet-kozan.github.io/pdf-parse/pdf/bitcoin.pdf'});
312
+
const result = await parser.getText()
313
+
console.log(result.text)
310
314
</script>
311
315
```
312
316
@@ -325,21 +329,7 @@ try {
325
329
326
330
327
331
328
-
### Worker Configuration
329
332
330
-
In browser environments, `pdf-parse` requires a separate worker file to process PDFs in a background thread. By default, `pdf-parse` automatically loads the worker from the jsDelivr CDN. However, you can configure a custom worker source if needed.
331
-
332
-
**When to Configure Worker Source:**
333
-
- Using a custom build of`pdf-parse`
334
-
- Self-hosting worker files for security or offline requirements
Copy file name to clipboardExpand all lines: README.worker.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,4 +56,22 @@ PDFParse.setWorker(workerUrl);
56
56
- Electron/NW.js packaging with non-standard import paths
57
57
- Self-hosting worker files for offline or security requirements
58
58
59
-
If you don't need to set a custom worker, you can ignore this file — `pdf-parse` will pick a sensible default.
59
+
60
+
61
+
62
+
63
+
### Browser Worker Configuration
64
+
65
+
In browser environments, `pdf-parse` requires a separate worker file to process PDFs in a background thread. By default, `pdf-parse` automatically loads the worker from the jsDelivr CDN. However, you can configure a custom worker source if needed.
66
+
67
+
**When to Configure Worker Source:**
68
+
- Using a custom build of `pdf-parse`
69
+
- Self-hosting worker files for security or offline requirements
0 commit comments