Skip to content

Commit

Permalink
feat: updgrade PDF.js to v4.3 (#13)
Browse files Browse the repository at this point in the history
* feat: updgrade PDF.js to v4.3

* fix: linting issues

* fix: Polyfill for `Promise.withResolvers`

* chore: update imports

* chore: update imports

* chore: update readme
  • Loading branch information
johannschopplich authored Jun 24, 2024
1 parent 4664ee2 commit d128424
Show file tree
Hide file tree
Showing 13 changed files with 3,664 additions and 3,802 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This library is also intended as a modern alternative to the unmaintained but st
## PDF.js Compatibility

> [!NOTE]
> This package is currently using PDF.js v4.0.189.
> This package is currently using PDF.js v4.3.136.
## Installation

Expand Down Expand Up @@ -138,7 +138,9 @@ function getResolvedPDFJS(): Promise<PDFJS>;
### `getMeta`

```ts
function getMeta(data: BinaryData | PDFDocumentProxy): Promise<{
function getMeta(
data: DocumentInitParameters["data"] | PDFDocumentProxy,
): Promise<{
info: Record<string, any>;
metadata: Record<string, any>;
}>;
Expand All @@ -150,7 +152,7 @@ Extracts all text from a PDF. If `mergePages` is set to `true`, the text of all

```ts
function extractText(
data: BinaryData | PDFDocumentProxy,
data: DocumentInitParameters["data"] | PDFDocumentProxy,
{ mergePages }?: { mergePages?: boolean },
): Promise<{
totalPages: number;
Expand Down Expand Up @@ -194,7 +196,7 @@ await writeFile("dummy-page-1.png", Buffer.from(result));

```ts
declare function renderPageAsImage(
data: BinaryData,
data: DocumentInitParameters["data"],
pageNumber: number,
options?: {
canvas?: () => Promise<typeof import("canvas")>;
Expand Down
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import unjs from "eslint-config-unjs";

// https://github.com/unjs/eslint-config
export default unjs();
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "unpdf",
"type": "module",
"version": "0.10.1",
"packageManager": "pnpm@8.15.6",
"packageManager": "pnpm@9.4.0",
"description": "Utilities to work with PDFs in Node.js, browser and workers",
"author": "Johann Schopplich <pkg@johannschopplich.com>",
"author": "Johann Schopplich <hello@johannschopplich.com>",
"license": "MIT",
"homepage": "https://github.com/unjs/unpdf#readme",
"repository": {
Expand Down Expand Up @@ -55,11 +55,11 @@
"build": "unbuild && node scripts/post-build.mjs",
"build:pdfjs": "rollup --config pdfjs.rollup.config.ts --configPlugin typescript && cp -R node_modules/pdfjs-dist/types dist",
"dev": "unbuild --stub",
"lint": "eslint \"**/*.{cjs,mjs,ts}\" --ignore-path .gitignore",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"format": "prettier \"**/*.{json,md,cjs,mjs,ts,yml}\" --write",
"format:check": "prettier \"**/*.{json,md,cjs,mjs,ts,yml}\" --check",
"release": "bumpp --commit --push --tag",
"release": "bumpp",
"test": "vitest",
"test:types": "tsc --noEmit"
},
Expand All @@ -68,28 +68,29 @@
},
"devDependencies": {
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.12.5",
"bumpp": "^9.4.0",
"eslint": "^8.57.0",
"eslint-config-unjs": "^0.2.1",
"@types/node": "^20.14.8",
"bumpp": "^9.4.1",
"eslint": "^9.5.0",
"eslint-config-unjs": "^0.3.2",
"fast-glob": "^3.3.2",
"pdfjs-dist": "^4.0.379",
"prettier": "^3.2.5",
"rollup": "^4.14.0",
"pdfjs-dist": "^4.3.136",
"prettier": "^3.3.2",
"rollup": "^4.18.0",
"tslib": "^2.6.3",
"typescript": "^5.4.4",
"unbuild": "^2.0.0",
"unenv": "^1.9.0",
"vitest": "^1.4.0"
"vitest": "^1.6.0"
},
"pnpm": {
"patchedDependencies": {
"pdfjs-dist@4.0.379": "patches/pdfjs-dist@4.0.379.patch"
"pdfjs-dist@4.3.136": "patches/pdfjs-dist@4.3.136.patch"
}
}
}
69 changes: 0 additions & 69 deletions patches/pdfjs-dist@4.0.379.patch

This file was deleted.

69 changes: 69 additions & 0 deletions patches/pdfjs-dist@4.3.136.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
diff --git a/build/pdf.mjs b/build/pdf.mjs
index 003035596c3797888692cafd43f9466f96607d55..f2036123445534bc60bf63d7a778462326ddc358 100644
--- a/build/pdf.mjs
+++ b/build/pdf.mjs
@@ -20,6 +20,7 @@
* JavaScript code in this page
*/

+export async function __main__() {
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
@@ -19416,6 +19417,55 @@ var __webpack_exports__setLayerDimensions = __webpack_exports__.setLayerDimensio
var __webpack_exports__shadow = __webpack_exports__.shadow;
var __webpack_exports__updateTextLayer = __webpack_exports__.updateTextLayer;
var __webpack_exports__version = __webpack_exports__.version;
-export { __webpack_exports__AbortException as AbortException, __webpack_exports__AnnotationEditorLayer as AnnotationEditorLayer, __webpack_exports__AnnotationEditorParamsType as AnnotationEditorParamsType, __webpack_exports__AnnotationEditorType as AnnotationEditorType, __webpack_exports__AnnotationEditorUIManager as AnnotationEditorUIManager, __webpack_exports__AnnotationLayer as AnnotationLayer, __webpack_exports__AnnotationMode as AnnotationMode, __webpack_exports__CMapCompressionType as CMapCompressionType, __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__DOMSVGFactory as DOMSVGFactory, __webpack_exports__DrawLayer as DrawLayer, __webpack_exports__FeatureTest as FeatureTest, __webpack_exports__GlobalWorkerOptions as GlobalWorkerOptions, __webpack_exports__ImageKind as ImageKind, __webpack_exports__InvalidPDFException as InvalidPDFException, __webpack_exports__MissingPDFException as MissingPDFException, __webpack_exports__OPS as OPS, __webpack_exports__Outliner as Outliner, __webpack_exports__PDFDataRangeTransport as PDFDataRangeTransport, __webpack_exports__PDFDateString as PDFDateString, __webpack_exports__PDFWorker as PDFWorker, __webpack_exports__PasswordResponses as PasswordResponses, __webpack_exports__PermissionFlag as PermissionFlag, __webpack_exports__PixelsPerInch as PixelsPerInch, __webpack_exports__RenderingCancelledException as RenderingCancelledException, __webpack_exports__TextLayer as TextLayer, __webpack_exports__UnexpectedResponseException as UnexpectedResponseException, __webpack_exports__Util as Util, __webpack_exports__VerbosityLevel as VerbosityLevel, __webpack_exports__XfaLayer as XfaLayer, __webpack_exports__build as build, __webpack_exports__createValidAbsoluteUrl as createValidAbsoluteUrl, __webpack_exports__fetchData as fetchData, __webpack_exports__getDocument as getDocument, __webpack_exports__getFilenameFromUrl as getFilenameFromUrl, __webpack_exports__getPdfFilenameFromUrl as getPdfFilenameFromUrl, __webpack_exports__getXfaPageViewport as getXfaPageViewport, __webpack_exports__isDataScheme as isDataScheme, __webpack_exports__isPdfFile as isPdfFile, __webpack_exports__noContextMenu as noContextMenu, __webpack_exports__normalizeUnicode as normalizeUnicode, __webpack_exports__renderTextLayer as renderTextLayer, __webpack_exports__setLayerDimensions as setLayerDimensions, __webpack_exports__shadow as shadow, __webpack_exports__updateTextLayer as updateTextLayer, __webpack_exports__version as version };
+// export { __webpack_exports__AbortException as AbortException, __webpack_exports__AnnotationEditorLayer as AnnotationEditorLayer, __webpack_exports__AnnotationEditorParamsType as AnnotationEditorParamsType, __webpack_exports__AnnotationEditorType as AnnotationEditorType, __webpack_exports__AnnotationEditorUIManager as AnnotationEditorUIManager, __webpack_exports__AnnotationLayer as AnnotationLayer, __webpack_exports__AnnotationMode as AnnotationMode, __webpack_exports__CMapCompressionType as CMapCompressionType, __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__DOMSVGFactory as DOMSVGFactory, __webpack_exports__DrawLayer as DrawLayer, __webpack_exports__FeatureTest as FeatureTest, __webpack_exports__GlobalWorkerOptions as GlobalWorkerOptions, __webpack_exports__ImageKind as ImageKind, __webpack_exports__InvalidPDFException as InvalidPDFException, __webpack_exports__MissingPDFException as MissingPDFException, __webpack_exports__OPS as OPS, __webpack_exports__Outliner as Outliner, __webpack_exports__PDFDataRangeTransport as PDFDataRangeTransport, __webpack_exports__PDFDateString as PDFDateString, __webpack_exports__PDFWorker as PDFWorker, __webpack_exports__PasswordResponses as PasswordResponses, __webpack_exports__PermissionFlag as PermissionFlag, __webpack_exports__PixelsPerInch as PixelsPerInch, __webpack_exports__RenderingCancelledException as RenderingCancelledException, __webpack_exports__TextLayer as TextLayer, __webpack_exports__UnexpectedResponseException as UnexpectedResponseException, __webpack_exports__Util as Util, __webpack_exports__VerbosityLevel as VerbosityLevel, __webpack_exports__XfaLayer as XfaLayer, __webpack_exports__build as build, __webpack_exports__createValidAbsoluteUrl as createValidAbsoluteUrl, __webpack_exports__fetchData as fetchData, __webpack_exports__getDocument as getDocument, __webpack_exports__getFilenameFromUrl as getFilenameFromUrl, __webpack_exports__getPdfFilenameFromUrl as getPdfFilenameFromUrl, __webpack_exports__getXfaPageViewport as getXfaPageViewport, __webpack_exports__isDataScheme as isDataScheme, __webpack_exports__isPdfFile as isPdfFile, __webpack_exports__noContextMenu as noContextMenu, __webpack_exports__normalizeUnicode as normalizeUnicode, __webpack_exports__renderTextLayer as renderTextLayer, __webpack_exports__setLayerDimensions as setLayerDimensions, __webpack_exports__shadow as shadow, __webpack_exports__updateTextLayer as updateTextLayer, __webpack_exports__version as version };
+return {
+ AbortException: __webpack_exports__AbortException,
+ AnnotationEditorLayer: __webpack_exports__AnnotationEditorLayer,
+ AnnotationEditorParamsType: __webpack_exports__AnnotationEditorParamsType,
+ AnnotationEditorType: __webpack_exports__AnnotationEditorType,
+ AnnotationEditorUIManager: __webpack_exports__AnnotationEditorUIManager,
+ AnnotationLayer: __webpack_exports__AnnotationLayer,
+ AnnotationMode: __webpack_exports__AnnotationMode,
+ CMapCompressionType: __webpack_exports__CMapCompressionType,
+ ColorPicker: __webpack_exports__ColorPicker,
+ DOMSVGFactory: __webpack_exports__DOMSVGFactory,
+ DrawLayer: __webpack_exports__DrawLayer,
+ FeatureTest: __webpack_exports__FeatureTest,
+ GlobalWorkerOptions: __webpack_exports__GlobalWorkerOptions,
+ ImageKind: __webpack_exports__ImageKind,
+ InvalidPDFException: __webpack_exports__InvalidPDFException,
+ MissingPDFException: __webpack_exports__MissingPDFException,
+ OPS: __webpack_exports__OPS,
+ Outliner: __webpack_exports__Outliner,
+ PDFDataRangeTransport: __webpack_exports__PDFDataRangeTransport,
+ PDFDateString: __webpack_exports__PDFDateString,
+ PDFWorker: __webpack_exports__PDFWorker,
+ PasswordResponses: __webpack_exports__PasswordResponses,
+ PermissionFlag: __webpack_exports__PermissionFlag,
+ PixelsPerInch: __webpack_exports__PixelsPerInch,
+ RenderingCancelledException: __webpack_exports__RenderingCancelledException,
+ TextLayer: __webpack_exports__TextLayer,
+ UnexpectedResponseException: __webpack_exports__UnexpectedResponseException,
+ Util: __webpack_exports__Util,
+ VerbosityLevel: __webpack_exports__VerbosityLevel,
+ XfaLayer: __webpack_exports__XfaLayer,
+ build: __webpack_exports__build,
+ createValidAbsoluteUrl: __webpack_exports__createValidAbsoluteUrl,
+ fetchData: __webpack_exports__fetchData,
+ getDocument: __webpack_exports__getDocument,
+ getFilenameFromUrl: __webpack_exports__getFilenameFromUrl,
+ getPdfFilenameFromUrl: __webpack_exports__getPdfFilenameFromUrl,
+ getXfaPageViewport: __webpack_exports__getXfaPageViewport,
+ isDataScheme: __webpack_exports__isDataScheme,
+ isPdfFile: __webpack_exports__isPdfFile,
+ noContextMenu: __webpack_exports__noContextMenu,
+ normalizeUnicode: __webpack_exports__normalizeUnicode,
+ renderTextLayer: __webpack_exports__renderTextLayer,
+ setLayerDimensions: __webpack_exports__setLayerDimensions,
+ shadow: __webpack_exports__shadow,
+ updateTextLayer: __webpack_exports__updateTextLayer,
+ version: __webpack_exports__version
+}
+}

//# sourceMappingURL=pdf.mjs.map
Loading

0 comments on commit d128424

Please sign in to comment.