@pdfme/converter 5.3.11 → 5.3.12-dev.2
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 +8 -7
- package/dist/cjs/src/index.browser.js.map +1 -1
- package/dist/cjs/src/index.node.js +15 -7
- package/dist/cjs/src/index.node.js.map +1 -1
- package/dist/esm/src/index.browser.js +7 -6
- package/dist/esm/src/index.browser.js.map +1 -1
- package/dist/esm/src/index.node.js +12 -7
- 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 -7
- package/src/index.node.ts +13 -7
@@ -38,12 +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
|
42
|
-
const
|
41
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
42
|
+
const pdf_worker_entry_js_1 = __importDefault(require("pdfjs-dist/build/pdf.worker.entry.js"));
|
43
43
|
const pdf2img_js_1 = require("./pdf2img.js");
|
44
44
|
const pdf2size_js_1 = require("./pdf2size.js");
|
45
|
-
|
46
|
-
pdfjsLib.GlobalWorkerOptions.workerSrc = pdf_worker_js_1.default;
|
45
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = pdf_worker_entry_js_1.default;
|
47
46
|
function dataURLToArrayBuffer(dataURL) {
|
48
47
|
// Split out the actual base64 string from the data URL scheme
|
49
48
|
const base64String = dataURL.split(',')[1];
|
@@ -65,9 +64,11 @@ const pdf2img = async (pdf, options = {}) => (0, pdf2img_js_1.pdf2img)(pdf, opti
|
|
65
64
|
canvas.height = height;
|
66
65
|
return canvas;
|
67
66
|
},
|
68
|
-
canvasToArrayBuffer: (canvas, imageType) =>
|
69
|
-
|
70
|
-
|
67
|
+
canvasToArrayBuffer: (canvas, imageType) => {
|
68
|
+
// Using type assertion to handle the canvas method
|
69
|
+
const dataUrl = canvas.toDataURL(`image/${imageType}`);
|
70
|
+
return dataURLToArrayBuffer(dataUrl);
|
71
|
+
},
|
71
72
|
});
|
72
73
|
exports.pdf2img = pdf2img;
|
73
74
|
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,+FAA+D;AAC/D,6CAAmE;AACnE,+CAAuE;AAEvE,QAAQ,CAAC,mBAAmB,CAAC,SAAS,GAAG,6BAAgC,CAAC;AAE1E,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,UA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this && this.__importDefault) || function (mod) {
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
37
|
+
};
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
36
39
|
exports.img2pdf = exports.pdf2size = exports.pdf2img = void 0;
|
40
|
+
const pdfjsLib = __importStar(require("pdfjs-dist/legacy/build/pdf"));
|
41
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
42
|
+
const pdf_worker_js_1 = __importDefault(require("pdfjs-dist/legacy/build/pdf.worker.js"));
|
37
43
|
const canvas_1 = require("canvas");
|
38
44
|
const pdf2img_js_1 = require("./pdf2img.js");
|
39
45
|
const pdf2size_js_1 = require("./pdf2size.js");
|
40
|
-
|
41
|
-
const pdfjsLib = __importStar(require("pdfjs-dist/legacy/build/pdf"));
|
46
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = pdf_worker_js_1.default;
|
42
47
|
const pdf2img = async (pdf, options = {}) => (0, pdf2img_js_1.pdf2img)(pdf, options, {
|
43
48
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
44
49
|
createCanvas: (width, height) => (0, canvas_1.createCanvas)(width, height),
|
45
|
-
canvasToArrayBuffer: (canvas
|
46
|
-
//
|
47
|
-
const
|
48
|
-
//
|
49
|
-
|
50
|
+
canvasToArrayBuffer: (canvas) => {
|
51
|
+
// Using a more specific type for the canvas from the 'canvas' package
|
52
|
+
const nodeCanvas = canvas;
|
53
|
+
// Get buffer from the canvas - using the synchronous version without parameters
|
54
|
+
// This will use the default PNG format
|
55
|
+
const buffer = nodeCanvas.toBuffer();
|
56
|
+
// Convert to ArrayBuffer
|
57
|
+
return new Uint8Array(buffer).buffer;
|
50
58
|
},
|
51
59
|
});
|
52
60
|
exports.pdf2img = pdf2img;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../../../src/index.node.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.node.js","sourceRoot":"","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ib from 'pdfjs-dist';
|
2
|
-
// @ts-expect-error
|
3
|
-
import PDFJSWorker from 'pdfjs-dist/
|
2
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
3
|
+
import PDFJSWorker from 'pdfjs-dist/build/pdf.worker.entry.js';
|
4
4
|
import { pdf2img as _pdf2img } from './pdf2img.js';
|
5
5
|
import { pdf2size as _pdf2size } from './pdf2size.js';
|
6
|
-
// @ts-ignore
|
7
6
|
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker;
|
8
7
|
function dataURLToArrayBuffer(dataURL) {
|
9
8
|
// Split out the actual base64 string from the data URL scheme
|
@@ -26,9 +25,11 @@ export const pdf2img = async (pdf, options = {}) => _pdf2img(pdf, options, {
|
|
26
25
|
canvas.height = height;
|
27
26
|
return canvas;
|
28
27
|
},
|
29
|
-
canvasToArrayBuffer: (canvas, imageType) =>
|
30
|
-
|
31
|
-
|
28
|
+
canvasToArrayBuffer: (canvas, imageType) => {
|
29
|
+
// Using type assertion to handle the canvas method
|
30
|
+
const dataUrl = canvas.toDataURL(`image/${imageType}`);
|
31
|
+
return dataURLToArrayBuffer(dataUrl);
|
32
|
+
},
|
32
33
|
});
|
33
34
|
export const pdf2size = async (pdf, options = {}) => _pdf2size(pdf, options, {
|
34
35
|
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,sCAAsC,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAkB,MAAM,cAAc,CAAC;AACnE,O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zC,mDAAmD;QACnD,MAAM,OAAO,GAAI,MAA4B,CAAC,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;QAC9E,OAAO,oBAAoB,CAAC,OAAO,CAAC,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,16 +1,21 @@
|
|
1
|
+
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';
|
2
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
3
|
+
import PDFJSWorker from 'pdfjs-dist/legacy/build/pdf.worker.js';
|
1
4
|
import { createCanvas } from 'canvas';
|
2
5
|
import { pdf2img as _pdf2img } from './pdf2img.js';
|
3
6
|
import { pdf2size as _pdf2size } from './pdf2size.js';
|
4
|
-
|
5
|
-
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';
|
7
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker;
|
6
8
|
export const pdf2img = async (pdf, options = {}) => _pdf2img(pdf, options, {
|
7
9
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
8
10
|
createCanvas: (width, height) => createCanvas(width, height),
|
9
|
-
canvasToArrayBuffer: (canvas
|
10
|
-
//
|
11
|
-
const
|
12
|
-
//
|
13
|
-
|
11
|
+
canvasToArrayBuffer: (canvas) => {
|
12
|
+
// Using a more specific type for the canvas from the 'canvas' package
|
13
|
+
const nodeCanvas = canvas;
|
14
|
+
// Get buffer from the canvas - using the synchronous version without parameters
|
15
|
+
// This will use the default PNG format
|
16
|
+
const buffer = nodeCanvas.toBuffer();
|
17
|
+
// Convert to ArrayBuffer
|
18
|
+
return new Uint8Array(buffer).buffer;
|
14
19
|
},
|
15
20
|
});
|
16
21
|
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;
|
1
|
+
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../../../src/index.node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,6BAA6B,CAAC;AACxD,6FAA6F;AAC7F,OAAO,WAAW,MAAM,uCAAuC,CAAC;AAChE,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;AAEvE,QAAQ,CAAC,mBAAmB,CAAC,SAAS,GAAG,WAAgC,CAAC;AAE1E,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.2",
|
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,10 @@
|
|
1
1
|
import * as pdfjsLib from 'pdfjs-dist';
|
2
|
-
// @ts-expect-error
|
3
|
-
import PDFJSWorker from 'pdfjs-dist/
|
2
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
3
|
+
import PDFJSWorker from 'pdfjs-dist/build/pdf.worker.entry.js';
|
4
4
|
import { pdf2img as _pdf2img, Pdf2ImgOptions } from './pdf2img.js';
|
5
5
|
import { pdf2size as _pdf2size, Pdf2SizeOptions } from './pdf2size.js';
|
6
6
|
|
7
|
-
|
8
|
-
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker;
|
7
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker as unknown as string;
|
9
8
|
|
10
9
|
function dataURLToArrayBuffer(dataURL: string): ArrayBuffer {
|
11
10
|
// Split out the actual base64 string from the data URL scheme
|
@@ -37,9 +36,11 @@ export const pdf2img = async (
|
|
37
36
|
canvas.height = height;
|
38
37
|
return canvas;
|
39
38
|
},
|
40
|
-
canvasToArrayBuffer: (canvas, imageType) =>
|
41
|
-
//
|
42
|
-
|
39
|
+
canvasToArrayBuffer: (canvas, imageType) => {
|
40
|
+
// Using type assertion to handle the canvas method
|
41
|
+
const dataUrl = (canvas as HTMLCanvasElement).toDataURL(`image/${imageType}`);
|
42
|
+
return dataURLToArrayBuffer(dataUrl);
|
43
|
+
},
|
43
44
|
});
|
44
45
|
|
45
46
|
export const pdf2size = async (pdf: ArrayBuffer | Uint8Array, options: Pdf2SizeOptions = {}) =>
|
package/src/index.node.ts
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';
|
2
|
+
// @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
|
3
|
+
import PDFJSWorker from 'pdfjs-dist/legacy/build/pdf.worker.js';
|
1
4
|
import { createCanvas } from 'canvas';
|
2
5
|
import { pdf2img as _pdf2img, Pdf2ImgOptions } from './pdf2img.js';
|
3
6
|
import { pdf2size as _pdf2size, Pdf2SizeOptions } from './pdf2size.js';
|
4
|
-
|
5
|
-
|
7
|
+
|
8
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker as unknown as string;
|
6
9
|
|
7
10
|
export const pdf2img = async (
|
8
11
|
pdf: ArrayBuffer | Uint8Array,
|
@@ -11,11 +14,14 @@ export const pdf2img = async (
|
|
11
14
|
_pdf2img(pdf, options, {
|
12
15
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
13
16
|
createCanvas: (width, height) => createCanvas(width, height) as unknown as HTMLCanvasElement,
|
14
|
-
canvasToArrayBuffer: (canvas
|
15
|
-
//
|
16
|
-
const
|
17
|
-
//
|
18
|
-
|
17
|
+
canvasToArrayBuffer: (canvas) => {
|
18
|
+
// Using a more specific type for the canvas from the 'canvas' package
|
19
|
+
const nodeCanvas = canvas as unknown as import('canvas').Canvas;
|
20
|
+
// Get buffer from the canvas - using the synchronous version without parameters
|
21
|
+
// This will use the default PNG format
|
22
|
+
const buffer = nodeCanvas.toBuffer();
|
23
|
+
// Convert to ArrayBuffer
|
24
|
+
return new Uint8Array(buffer).buffer;
|
19
25
|
},
|
20
26
|
});
|
21
27
|
|