@pdfme/converter 5.3.11 → 5.3.12-dev.1
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/dist/cjs/src/index.browser.js +7 -5
- package/dist/cjs/src/index.browser.js.map +1 -1
- package/dist/cjs/src/index.node.js +8 -6
- package/dist/cjs/src/index.node.js.map +1 -1
- package/dist/esm/src/index.browser.js +7 -5
- package/dist/esm/src/index.browser.js.map +1 -1
- package/dist/esm/src/index.node.js +8 -6
- package/dist/esm/src/index.node.js.map +1 -1
- package/dist/types/src/img2pdf.d.ts +2 -1
- package/package.json +3 -3
- package/src/img2pdf.ts +1 -1
- package/src/index.browser.ts +8 -6
- package/src/index.node.ts +8 -6
@@ -38,11 +38,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
39
|
exports.img2pdf = exports.pdf2size = exports.pdf2img = void 0;
|
40
40
|
const pdfjsLib = __importStar(require("pdfjs-dist"));
|
41
|
-
// @ts-expect-error
|
41
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
42
42
|
const pdf_worker_js_1 = __importDefault(require("pdfjs-dist/legacy/build/pdf.worker.js"));
|
43
43
|
const pdf2img_js_1 = require("./pdf2img.js");
|
44
44
|
const pdf2size_js_1 = require("./pdf2size.js");
|
45
|
-
// @ts-
|
45
|
+
// @ts-expect-error - Setting workerSrc is required but type definitions are incomplete
|
46
46
|
pdfjsLib.GlobalWorkerOptions.workerSrc = pdf_worker_js_1.default;
|
47
47
|
function dataURLToArrayBuffer(dataURL) {
|
48
48
|
// Split out the actual base64 string from the data URL scheme
|
@@ -65,9 +65,11 @@ const pdf2img = async (pdf, options = {}) => (0, pdf2img_js_1.pdf2img)(pdf, opti
|
|
65
65
|
canvas.height = height;
|
66
66
|
return canvas;
|
67
67
|
},
|
68
|
-
canvasToArrayBuffer: (canvas, imageType) =>
|
69
|
-
|
70
|
-
|
68
|
+
canvasToArrayBuffer: (canvas, imageType) => {
|
69
|
+
// Using type assertion to handle the canvas method
|
70
|
+
const dataUrl = canvas.toDataURL(`image/${imageType}`);
|
71
|
+
return dataURLToArrayBuffer(dataUrl);
|
72
|
+
},
|
71
73
|
});
|
72
74
|
exports.pdf2img = pdf2img;
|
73
75
|
const pdf2size = async (pdf, options = {}) => (0, pdf2size_js_1.pdf2size)(pdf, options, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,6FAA6F;AAC7F,0FAAgE;AAChE,6CAAmE;AACnE,+CAAuE;AAEvE,uFAAuF;AACvF,QAAQ,CAAC,mBAAmB,CAAC,SAAS,GAAG,uBAAsB,CAAC;AAEhE,SAAS,oBAAoB,CAAC,OAAe;IAC3C,8DAA8D;IAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3C,kDAAkD;IAClD,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAEtC,8CAA8C;IAC9C,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;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1 = require("./pdf2size.js");
|
40
|
-
// @ts-ignore
|
41
40
|
const pdfjsLib = __importStar(require("pdfjs-dist/legacy/build/pdf"));
|
42
41
|
const pdf2img = async (pdf, options = {}) => (0, pdf2img_js_1.pdf2img)(pdf, options, {
|
43
42
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
44
43
|
createCanvas: (width, height) => (0, canvas_1.createCanvas)(width, height),
|
45
|
-
canvasToArrayBuffer: (canvas
|
46
|
-
//
|
47
|
-
const
|
48
|
-
//
|
49
|
-
|
44
|
+
canvasToArrayBuffer: (canvas) => {
|
45
|
+
// Using a more specific type for the canvas from the 'canvas' package
|
46
|
+
const nodeCanvas = canvas;
|
47
|
+
// Get buffer from the canvas - using the synchronous version without parameters
|
48
|
+
// This will use the default PNG format
|
49
|
+
const buffer = nodeCanvas.toBuffer();
|
50
|
+
// Convert to ArrayBuffer
|
51
|
+
return new Uint8Array(buffer).buffer;
|
50
52
|
},
|
51
53
|
});
|
52
54
|
exports.pdf2img = pdf2img;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../../../src/index.node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,6CAAmE;AACnE,+CAAuE;AACvE,
|
1
|
+
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../../../src/index.node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,6CAAmE;AACnE,+CAAuE;AACvE,sEAAwD;AAEjD,MAAM,OAAO,GAAG,KAAK,EAC1B,GAA6B,EAC7B,UAA0B,EAAE,EACJ,EAAE,CAC1B,IAAA,oBAAQ,EAAC,GAAG,EAAE,OAAO,EAAE;IACrB,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO;IACvD,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,IAAA,qBAAY,EAAC,KAAK,EAAE,MAAM,CAAiC;IAC5F,mBAAmB,EAAE,CAAC,MAAM,EAAE,EAAE;QAC9B,sEAAsE;QACtE,MAAM,UAAU,GAAG,MAA4C,CAAC;QAChE,gFAAgF;QAChF,uCAAuC;QACvC,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QACrC,yBAAyB;QACzB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IACvC,CAAC;CACF,CAAC,CAAC;AAhBQ,QAAA,OAAO,WAgBf;AAEE,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA6B,EAAE,UAA2B,EAAE,EAAE,EAAE,CAC7F,IAAA,sBAAS,EAAC,GAAG,EAAE,OAAO,EAAE;IACtB,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO;CACxD,CAAC,CAAC;AAHQ,QAAA,QAAQ,YAGhB;AAEL,2CAAuC;AAA9B,qGAAA,OAAO,OAAA"}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import * as pdfjsLib from 'pdfjs-dist';
|
2
|
-
// @ts-expect-error
|
2
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
3
3
|
import PDFJSWorker from 'pdfjs-dist/legacy/build/pdf.worker.js';
|
4
4
|
import { pdf2img as _pdf2img } from './pdf2img.js';
|
5
5
|
import { pdf2size as _pdf2size } from './pdf2size.js';
|
6
|
-
// @ts-
|
6
|
+
// @ts-expect-error - Setting workerSrc is required but type definitions are incomplete
|
7
7
|
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker;
|
8
8
|
function dataURLToArrayBuffer(dataURL) {
|
9
9
|
// Split out the actual base64 string from the data URL scheme
|
@@ -26,9 +26,11 @@ export const pdf2img = async (pdf, options = {}) => _pdf2img(pdf, options, {
|
|
26
26
|
canvas.height = height;
|
27
27
|
return canvas;
|
28
28
|
},
|
29
|
-
canvasToArrayBuffer: (canvas, imageType) =>
|
30
|
-
|
31
|
-
|
29
|
+
canvasToArrayBuffer: (canvas, imageType) => {
|
30
|
+
// Using type assertion to handle the canvas method
|
31
|
+
const dataUrl = canvas.toDataURL(`image/${imageType}`);
|
32
|
+
return dataURLToArrayBuffer(dataUrl);
|
33
|
+
},
|
32
34
|
});
|
33
35
|
export const pdf2size = async (pdf, options = {}) => _pdf2size(pdf, options, {
|
34
36
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/index.browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/index.browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,6FAA6F;AAC7F,OAAO,WAAW,MAAM,uCAAuC,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAkB,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAmB,MAAM,eAAe,CAAC;AAEvE,uFAAuF;AACvF,QAAQ,CAAC,mBAAmB,CAAC,SAAS,GAAG,WAAsB,CAAC;AAEhE,SAAS,oBAAoB,CAAC,OAAe;IAC3C,8DAA8D;IAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3C,kDAAkD;IAClD,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAEtC,8CAA8C;IAC9C,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,IAAI,UAAU,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AM,cAAc,CAAC"}
|
@@ -1,16 +1,18 @@
|
|
1
1
|
import { createCanvas } from 'canvas';
|
2
2
|
import { pdf2img as _pdf2img } from './pdf2img.js';
|
3
3
|
import { pdf2size as _pdf2size } from './pdf2size.js';
|
4
|
-
// @ts-ignore
|
5
4
|
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';
|
6
5
|
export const pdf2img = async (pdf, options = {}) => _pdf2img(pdf, options, {
|
7
6
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
8
7
|
createCanvas: (width, height) => createCanvas(width, height),
|
9
|
-
canvasToArrayBuffer: (canvas
|
10
|
-
//
|
11
|
-
const
|
12
|
-
//
|
13
|
-
|
8
|
+
canvasToArrayBuffer: (canvas) => {
|
9
|
+
// Using a more specific type for the canvas from the 'canvas' package
|
10
|
+
const nodeCanvas = canvas;
|
11
|
+
// Get buffer from the canvas - using the synchronous version without parameters
|
12
|
+
// This will use the default PNG format
|
13
|
+
const buffer = nodeCanvas.toBuffer();
|
14
|
+
// Convert to ArrayBuffer
|
15
|
+
return new Uint8Array(buffer).buffer;
|
14
16
|
},
|
15
17
|
});
|
16
18
|
export const pdf2size = async (pdf, options = {}) => _pdf2size(pdf, options, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../../../src/index.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAkB,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAmB,MAAM,eAAe,CAAC;AACvE,
|
1
|
+
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../../../src/index.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAkB,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAmB,MAAM,eAAe,CAAC;AACvE,OAAO,KAAK,QAAQ,MAAM,6BAA6B,CAAC;AAExD,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAC1B,GAA6B,EAC7B,UAA0B,EAAE,EACJ,EAAE,CAC1B,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE;IACrB,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO;IACvD,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAiC;IAC5F,mBAAmB,EAAE,CAAC,MAAM,EAAE,EAAE;QAC9B,sEAAsE;QACtE,MAAM,UAAU,GAAG,MAA4C,CAAC;QAChE,gFAAgF;QAChF,uCAAuC;QACvC,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QACrC,yBAAyB;QACzB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IACvC,CAAC;CACF,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA6B,EAAE,UAA2B,EAAE,EAAE,EAAE,CAC7F,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE;IACtB,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO;CACxD,CAAC,CAAC;AAEL,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { ImageType } from './types.js';
|
2
|
-
|
2
|
+
interface Img2PdfOptions {
|
3
3
|
scale?: number;
|
4
4
|
imageType?: ImageType;
|
5
5
|
}
|
6
6
|
export declare function img2pdf(imgs: ArrayBuffer[], options?: Img2PdfOptions): Promise<ArrayBuffer>;
|
7
|
+
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/converter",
|
3
|
-
"version": "5.3.
|
3
|
+
"version": "5.3.12-dev.1",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -38,13 +38,13 @@
|
|
38
38
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
39
39
|
"build:esm": "tsc -p tsconfig.esm.json",
|
40
40
|
"clean": "rimraf dist",
|
41
|
-
"lint": "eslint --ext .ts src --config eslint.config.mjs
|
41
|
+
"lint": "eslint --ext .ts src --config eslint.config.mjs",
|
42
42
|
"test": "jest",
|
43
43
|
"prune": "ts-prune src",
|
44
44
|
"prettier": "prettier --write 'src/**/*.ts'"
|
45
45
|
},
|
46
46
|
"dependencies": {
|
47
|
-
"@pdfme/common": "
|
47
|
+
"@pdfme/common": "file:../common",
|
48
48
|
"@pdfme/pdf-lib": "*",
|
49
49
|
"pdfjs-dist": "^3.11.174"
|
50
50
|
},
|
package/src/img2pdf.ts
CHANGED
package/src/index.browser.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import * as pdfjsLib from 'pdfjs-dist';
|
2
|
-
// @ts-expect-error
|
2
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
3
3
|
import PDFJSWorker from 'pdfjs-dist/legacy/build/pdf.worker.js';
|
4
4
|
import { pdf2img as _pdf2img, Pdf2ImgOptions } from './pdf2img.js';
|
5
5
|
import { pdf2size as _pdf2size, Pdf2SizeOptions } from './pdf2size.js';
|
6
6
|
|
7
|
-
// @ts-
|
8
|
-
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker;
|
7
|
+
// @ts-expect-error - Setting workerSrc is required but type definitions are incomplete
|
8
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker as unknown;
|
9
9
|
|
10
10
|
function dataURLToArrayBuffer(dataURL: string): ArrayBuffer {
|
11
11
|
// Split out the actual base64 string from the data URL scheme
|
@@ -37,9 +37,11 @@ export const pdf2img = async (
|
|
37
37
|
canvas.height = height;
|
38
38
|
return canvas;
|
39
39
|
},
|
40
|
-
canvasToArrayBuffer: (canvas, imageType) =>
|
41
|
-
//
|
42
|
-
|
40
|
+
canvasToArrayBuffer: (canvas, imageType) => {
|
41
|
+
// Using type assertion to handle the canvas method
|
42
|
+
const dataUrl = (canvas as HTMLCanvasElement).toDataURL(`image/${imageType}`);
|
43
|
+
return dataURLToArrayBuffer(dataUrl);
|
44
|
+
},
|
43
45
|
});
|
44
46
|
|
45
47
|
export const pdf2size = async (pdf: ArrayBuffer | Uint8Array, options: Pdf2SizeOptions = {}) =>
|
package/src/index.node.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { createCanvas } from 'canvas';
|
2
2
|
import { pdf2img as _pdf2img, Pdf2ImgOptions } from './pdf2img.js';
|
3
3
|
import { pdf2size as _pdf2size, Pdf2SizeOptions } from './pdf2size.js';
|
4
|
-
// @ts-ignore
|
5
4
|
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';
|
6
5
|
|
7
6
|
export const pdf2img = async (
|
@@ -11,11 +10,14 @@ export const pdf2img = async (
|
|
11
10
|
_pdf2img(pdf, options, {
|
12
11
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
13
12
|
createCanvas: (width, height) => createCanvas(width, height) as unknown as HTMLCanvasElement,
|
14
|
-
canvasToArrayBuffer: (canvas
|
15
|
-
//
|
16
|
-
const
|
17
|
-
//
|
18
|
-
|
13
|
+
canvasToArrayBuffer: (canvas) => {
|
14
|
+
// Using a more specific type for the canvas from the 'canvas' package
|
15
|
+
const nodeCanvas = canvas as unknown as import('canvas').Canvas;
|
16
|
+
// Get buffer from the canvas - using the synchronous version without parameters
|
17
|
+
// This will use the default PNG format
|
18
|
+
const buffer = nodeCanvas.toBuffer();
|
19
|
+
// Convert to ArrayBuffer
|
20
|
+
return new Uint8Array(buffer).buffer;
|
19
21
|
},
|
20
22
|
});
|
21
23
|
|