@pdfme/converter 5.3.7-dev.1 → 5.3.7
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/__tests__/index.test.js +0 -50
- package/dist/cjs/__tests__/index.test.js.map +1 -1
- package/dist/cjs/src/index.browser.js +1 -3
- package/dist/cjs/src/index.browser.js.map +1 -1
- package/dist/cjs/src/index.node.js +1 -3
- package/dist/cjs/src/index.node.js.map +1 -1
- package/dist/cjs/src/pdf2img.js.map +1 -1
- package/dist/esm/__tests__/index.test.js +1 -51
- package/dist/esm/__tests__/index.test.js.map +1 -1
- package/dist/esm/src/index.browser.js +0 -1
- package/dist/esm/src/index.browser.js.map +1 -1
- package/dist/esm/src/index.node.js +0 -1
- package/dist/esm/src/index.node.js.map +1 -1
- package/dist/esm/src/pdf2img.js.map +1 -1
- package/dist/types/src/index.browser.d.ts +0 -1
- package/dist/types/src/index.node.d.ts +0 -1
- package/dist/types/src/pdf2img.d.ts +1 -1
- package/package.json +1 -2
- package/src/index.browser.ts +0 -2
- package/src/index.node.ts +0 -2
- package/src/pdf2img.ts +2 -1
- package/dist/cjs/src/img2pdf.js +0 -39
- package/dist/cjs/src/img2pdf.js.map +0 -1
- package/dist/esm/src/img2pdf.js +0 -35
- package/dist/esm/src/img2pdf.js.map +0 -1
- package/dist/types/src/img2pdf.d.ts +0 -6
- package/src/img2pdf.ts +0 -47
- package/src/types.d.ts +0 -1
@@ -55,56 +55,6 @@ describe('pdf2img tests', () => {
|
|
55
55
|
await expect((0, index_node_1.pdf2img)(emptyBuffer, { scale: 1 })).rejects.toThrow('The PDF file is empty, i.e. its size is zero by');
|
56
56
|
});
|
57
57
|
});
|
58
|
-
describe('img2pdf tests', () => {
|
59
|
-
let jpegImage;
|
60
|
-
let pngImage;
|
61
|
-
beforeAll(async () => {
|
62
|
-
// Create test images using pdf2img for testing
|
63
|
-
const pdf = await (0, generator_1.generate)({
|
64
|
-
template: {
|
65
|
-
schemas: [
|
66
|
-
[
|
67
|
-
{
|
68
|
-
name: 'field1',
|
69
|
-
type: 'text',
|
70
|
-
content: 'Type Something...',
|
71
|
-
position: { x: 10, y: 20 },
|
72
|
-
width: 45,
|
73
|
-
height: 10,
|
74
|
-
},
|
75
|
-
],
|
76
|
-
],
|
77
|
-
basePdf: { width: 210, height: 297, padding: [20, 10, 20, 10] },
|
78
|
-
pdfmeVersion: '5.2.16',
|
79
|
-
},
|
80
|
-
inputs: [{}],
|
81
|
-
});
|
82
|
-
const images = await (0, index_node_1.pdf2img)(pdf.buffer, { scale: 1 });
|
83
|
-
jpegImage = images[0];
|
84
|
-
pngImage = images[0]; // Using same image for both tests
|
85
|
-
});
|
86
|
-
test('converts single image to PDF', async () => {
|
87
|
-
const pdf = await (0, index_node_1.img2pdf)([jpegImage]);
|
88
|
-
expect(pdf).toBeInstanceOf(ArrayBuffer);
|
89
|
-
expect(pdf.byteLength).toBeGreaterThan(0);
|
90
|
-
});
|
91
|
-
test('converts multiple images to single PDF', async () => {
|
92
|
-
const pdf = await (0, index_node_1.img2pdf)([jpegImage, pngImage]);
|
93
|
-
expect(pdf).toBeInstanceOf(ArrayBuffer);
|
94
|
-
expect(pdf.byteLength).toBeGreaterThan(0);
|
95
|
-
});
|
96
|
-
test('handles scale option', async () => {
|
97
|
-
const pdf = await (0, index_node_1.img2pdf)([jpegImage], { scale: 0.5 });
|
98
|
-
expect(pdf.byteLength).toBeGreaterThan(0);
|
99
|
-
});
|
100
|
-
test('throws error for empty input', async () => {
|
101
|
-
await expect((0, index_node_1.img2pdf)([])).rejects.toThrow('Input must be a non-empty array');
|
102
|
-
});
|
103
|
-
test('throws error for invalid image', async () => {
|
104
|
-
const invalidImage = new ArrayBuffer(10);
|
105
|
-
await expect((0, index_node_1.img2pdf)([invalidImage])).rejects.toThrow('Failed to process image');
|
106
|
-
});
|
107
|
-
});
|
108
58
|
describe('pdf2size tests', () => {
|
109
59
|
let pdfArrayBuffer;
|
110
60
|
beforeAll(async () => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../__tests__/index.test.ts"],"names":[],"mappings":";;AAAA,aAAa;AACb,gDAA4C;AAC5C,
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../__tests__/index.test.ts"],"names":[],"mappings":";;AAAA,aAAa;AACb,gDAA4C;AAC5C,kDAAqF;AAErF,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,cAA2B,CAAC;IAEhC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,GAAG,GAAG,MAAM,IAAA,oBAAQ,EAAC;YACzB,QAAQ,EAAE;gBACR,OAAO,EAAE;oBACP;wBACE;4BACE,IAAI,EAAE,QAAQ;4BACd,IAAI,EAAE,MAAM;4BACZ,OAAO,EAAE,mBAAmB;4BAC5B,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;4BAC1B,KAAK,EAAE,EAAE;4BACT,MAAM,EAAE,EAAE;yBACX;qBACF;iBACF;gBACD,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE;gBAC/D,YAAY,EAAE,QAAQ;aACvB;YACD,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;SACzB,CAAC,CAAC;QACH,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,MAAM,GAAG,MAAM,IAAA,oBAAW,EAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/D,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAA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KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,MAAM,CAAC,IAAA,qBAAY,EAAC,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACnE,iDAAiD,CAClD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.
|
29
|
+
exports.pdf2size = exports.pdf2img = void 0;
|
30
30
|
const pdfjsLib = __importStar(require("pdfjs-dist"));
|
31
31
|
// @ts-expect-error
|
32
32
|
const pdf_worker_js_1 = __importDefault(require("pdfjs-dist/legacy/build/pdf.worker.js"));
|
@@ -64,6 +64,4 @@ const pdf2size = async (pdf, options = {}) => (0, pdf2size_js_1.pdf2size)(pdf, o
|
|
64
64
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
65
65
|
});
|
66
66
|
exports.pdf2size = pdf2size;
|
67
|
-
var img2pdf_js_1 = require("./img2pdf.js");
|
68
|
-
Object.defineProperty(exports, "img2pdf", { enumerable: true, get: function () { return img2pdf_js_1.img2pdf; } });
|
69
67
|
//# sourceMappingURL=index.browser.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,mBAAmB;AACnB,0FAAgE;AACh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0B,EAAE,EAAE,EAAE,CAC9E,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;QAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,mBAAmB,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;IACzC,aAAa;IACb,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;CAC/D,CAAC,CAAC;AAZQ,QAAA,OAAO,WAYf;AAEE,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAgB,EAAE,UAA2B,EAAE,EAAE,EAAE,CAChF,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"}
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.
|
29
|
+
exports.pdf2size = exports.pdf2img = void 0;
|
30
30
|
const canvas_1 = require("canvas");
|
31
31
|
const pdf2img_js_1 = require("./pdf2img.js");
|
32
32
|
const pdf2size_js_1 = require("./pdf2size.js");
|
@@ -50,6 +50,4 @@ const pdf2size = async (pdf, options = {}) => (0, pdf2size_js_1.pdf2size)(pdf, o
|
|
50
50
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
51
51
|
});
|
52
52
|
exports.pdf2size = pdf2size;
|
53
|
-
var img2pdf_js_1 = require("./img2pdf.js");
|
54
|
-
Object.defineProperty(exports, "img2pdf", { enumerable: true, get: function () { return img2pdf_js_1.img2pdf; } });
|
55
53
|
//# sourceMappingURL=index.node.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../../../src/index.node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,6CAAmE;AACnE,+CAAuE;AACvE,sEAAwD;AACxD,mBAAmB;AACnB,6EAAsD;AAEtD,aAAa;AACb,QAAQ,CAAC,mBAAmB,CAAC,SAAS,GAAG,oBAAW,CAAC;AAE9C,MAAM,OAAO,GAAG,KAAK,EAAE,GAAgB,EAAE,UAA0B,EAAE,EAAE,EAAE,CAC9E,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,SAAS,EAAE,EAAE;QACzC,aAAa;QACb,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;QACrD,aAAa;QACb,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACvF,CAAC;CACF,CAAC,CAAC;AAVQ,QAAA,OAAO,WAUf;AAEE,MAAM,QAAQ,GAAG,K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,EAAE,EAAE,EAAE,CAChF,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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pdf2img.js","sourceRoot":"","sources":["../../../src/pdf2img.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"pdf2img.js","sourceRoot":"","sources":["../../../src/pdf2img.ts"],"names":[],"mappings":";;;AAsBO,KAAK,UAAU,OAAO,CAC3B,GAAgB,EAChB,UAA0B,EAAE,EAC5B,GAAgB;IAEhB,IAAI;QACF,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,SAAS,GAAG,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;QAC9D,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC;QAE5C,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,GAAG,GAAG,CAAC;QAE/D,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEjC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;QAE5C,MAAM,OAAO,GAAkB,EAAE,CAAC;QAElC,KAAK,IAAI,OAAO,GAAG,SAAS,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,EAAE,EAAE;YAC3D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAE7C,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7D,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;aAC5C;YAED,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAA6B,CAAC;YACpE,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;aACjD;YAED,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;YAChE,MAAM,WAAW,GAAG,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YAC3D,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SAC3B;QAED,OAAO,OAAO,CAAC;KAChB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,sCAAuC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;KACnF;AACH,CAAC;AA1CD,0BA0CC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// @ts-ignore
|
2
2
|
import { generate } from '@pdfme/generator';
|
3
|
-
import { pdf2img as nodePdf2Img, pdf2size as nodePdf2Size
|
3
|
+
import { pdf2img as nodePdf2Img, pdf2size as nodePdf2Size } from '../src/index.node';
|
4
4
|
describe('pdf2img tests', () => {
|
5
5
|
let pdfArrayBuffer;
|
6
6
|
beforeAll(async () => {
|
@@ -53,56 +53,6 @@ describe('pdf2img tests', () => {
|
|
53
53
|
await expect(nodePdf2Img(emptyBuffer, { scale: 1 })).rejects.toThrow('The PDF file is empty, i.e. its size is zero by');
|
54
54
|
});
|
55
55
|
});
|
56
|
-
describe('img2pdf tests', () => {
|
57
|
-
let jpegImage;
|
58
|
-
let pngImage;
|
59
|
-
beforeAll(async () => {
|
60
|
-
// Create test images using pdf2img for testing
|
61
|
-
const pdf = await generate({
|
62
|
-
template: {
|
63
|
-
schemas: [
|
64
|
-
[
|
65
|
-
{
|
66
|
-
name: 'field1',
|
67
|
-
type: 'text',
|
68
|
-
content: 'Type Something...',
|
69
|
-
position: { x: 10, y: 20 },
|
70
|
-
width: 45,
|
71
|
-
height: 10,
|
72
|
-
},
|
73
|
-
],
|
74
|
-
],
|
75
|
-
basePdf: { width: 210, height: 297, padding: [20, 10, 20, 10] },
|
76
|
-
pdfmeVersion: '5.2.16',
|
77
|
-
},
|
78
|
-
inputs: [{}],
|
79
|
-
});
|
80
|
-
const images = await nodePdf2Img(pdf.buffer, { scale: 1 });
|
81
|
-
jpegImage = images[0];
|
82
|
-
pngImage = images[0]; // Using same image for both tests
|
83
|
-
});
|
84
|
-
test('converts single image to PDF', async () => {
|
85
|
-
const pdf = await img2pdf([jpegImage]);
|
86
|
-
expect(pdf).toBeInstanceOf(ArrayBuffer);
|
87
|
-
expect(pdf.byteLength).toBeGreaterThan(0);
|
88
|
-
});
|
89
|
-
test('converts multiple images to single PDF', async () => {
|
90
|
-
const pdf = await img2pdf([jpegImage, pngImage]);
|
91
|
-
expect(pdf).toBeInstanceOf(ArrayBuffer);
|
92
|
-
expect(pdf.byteLength).toBeGreaterThan(0);
|
93
|
-
});
|
94
|
-
test('handles scale option', async () => {
|
95
|
-
const pdf = await img2pdf([jpegImage], { scale: 0.5 });
|
96
|
-
expect(pdf.byteLength).toBeGreaterThan(0);
|
97
|
-
});
|
98
|
-
test('throws error for empty input', async () => {
|
99
|
-
await expect(img2pdf([])).rejects.toThrow('Input must be a non-empty array');
|
100
|
-
});
|
101
|
-
test('throws error for invalid image', async () => {
|
102
|
-
const invalidImage = new ArrayBuffer(10);
|
103
|
-
await expect(img2pdf([invalidImage])).rejects.toThrow('Failed to process image');
|
104
|
-
});
|
105
|
-
});
|
106
56
|
describe('pdf2size tests', () => {
|
107
57
|
let pdfArrayBuffer;
|
108
58
|
beforeAll(async () => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../__tests__/index.test.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,QAAQ,IAAI,YAAY,EAAE,
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../__tests__/index.test.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErF,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,cAA2B,CAAC;IAEhC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC;YACzB,QAAQ,EAAE;gBACR,OAAO,EAAE;oBACP;wBACE;4BACE,IAAI,EAAE,QAAQ;4BACd,IAAI,EAAE,MAAM;4BACZ,OAAO,EAAE,mBAAmB;4BAC5B,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;4BAC1B,KAAK,EAAE,EAAE;4BACT,MAAM,EAAE,EAAE;yBACX;qBACF;iBACF;gBACD,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE;gBAC/D,YAAY,EAAE,QAAQ;aACvB;YACD,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;SACzB,CAAC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AAG,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,aAAa,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;QAC1C,MAAM,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACnE,iDAAiD,CAClD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -33,5 +33,4 @@ export const pdf2img = async (pdf, options = {}) => _pdf2img(pdf, options, {
|
|
33
33
|
export const pdf2size = async (pdf, options = {}) => _pdf2size(pdf, options, {
|
34
34
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
35
35
|
});
|
36
|
-
export { img2pdf } from './img2pdf.js';
|
37
36
|
//# sourceMappingURL=index.browser.js.map
|
@@ -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,mBAAmB;AACnB,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,aAAa;AACb,QAAQ,CAAC,m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,EAAE,GAAgB,EAAE,UAA0B,EAAE,EAAE,EAAE,CAC9E,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;QAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,mBAAmB,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;IACzC,aAAa;IACb,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;CAC/D,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAgB,EAAE,UAA2B,EAAE,EAAE,EAAE,CAChF,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"}
|
@@ -19,5 +19,4 @@ export const pdf2img = async (pdf, options = {}) => _pdf2img(pdf, options, {
|
|
19
19
|
export const pdf2size = async (pdf, options = {}) => _pdf2size(pdf, options, {
|
20
20
|
getDocument: (pdf) => pdfjsLib.getDocument(pdf).promise,
|
21
21
|
});
|
22
|
-
export { img2pdf } from './img2pdf.js';
|
23
22
|
//# sourceMappingURL=index.node.js.map
|
@@ -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,O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AC,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pdf2img.js","sourceRoot":"","sources":["../../../src/pdf2img.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"pdf2img.js","sourceRoot":"","sources":["../../../src/pdf2img.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,GAAgB,EAChB,UAA0B,EAAE,EAC5B,GAAgB;IAEhB,IAAI;QACF,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,SAAS,GAAG,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;QAC9D,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC;QAE5C,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,GAAG,GAAG,CAAC;QAE/D,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEjC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;QAE5C,MAAM,OAAO,GAAkB,EAAE,CAAC;QAElC,KAAK,IAAI,OAAO,GAAG,SAAS,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,EAAE,EAAE;YAC3D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAE7C,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7D,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;aAC5C;YAED,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAA6B,CAAC;YACpE,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;aACjD;YAED,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;YAChE,MAAM,WAAW,GAAG,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YAC3D,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SAC3B;QAED,OAAO,OAAO,CAAC;KAChB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,sCAAuC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;KACnF;AACH,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
2
|
-
|
2
|
+
type ImageType = 'jpeg' | 'png';
|
3
3
|
interface Environment {
|
4
4
|
getDocument: (pdf: ArrayBuffer) => Promise<PDFDocumentProxy>;
|
5
5
|
createCanvas: (width: number, height: number) => HTMLCanvasElement | OffscreenCanvas;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/converter",
|
3
|
-
"version": "5.3.7
|
3
|
+
"version": "5.3.7",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -45,7 +45,6 @@
|
|
45
45
|
},
|
46
46
|
"dependencies": {
|
47
47
|
"@pdfme/common": "*",
|
48
|
-
"@pdfme/pdf-lib": "*",
|
49
48
|
"pdfjs-dist": "^3.11.174"
|
50
49
|
},
|
51
50
|
"devDependencies": {
|
package/src/index.browser.ts
CHANGED
package/src/index.node.ts
CHANGED
package/src/pdf2img.ts
CHANGED
package/dist/cjs/src/img2pdf.js
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.img2pdf = void 0;
|
4
|
-
const pdf_lib_1 = require("@pdfme/pdf-lib");
|
5
|
-
async function img2pdf(imgs, options = {}) {
|
6
|
-
try {
|
7
|
-
const { scale = 1 } = options;
|
8
|
-
if (!Array.isArray(imgs) || imgs.length === 0) {
|
9
|
-
throw new Error('Input must be a non-empty array of image buffers');
|
10
|
-
}
|
11
|
-
const doc = await pdf_lib_1.PDFDocument.create();
|
12
|
-
for (const img of imgs) {
|
13
|
-
try {
|
14
|
-
const image = await doc.embedJpg(img).catch(async () => {
|
15
|
-
return await doc.embedPng(img);
|
16
|
-
});
|
17
|
-
const page = doc.addPage();
|
18
|
-
const { width, height } = image.scale(scale);
|
19
|
-
page.setSize(width, height);
|
20
|
-
page.drawImage(image, {
|
21
|
-
x: 0,
|
22
|
-
y: 0,
|
23
|
-
width,
|
24
|
-
height,
|
25
|
-
});
|
26
|
-
}
|
27
|
-
catch (error) {
|
28
|
-
throw new Error(`Failed to process image: ${error.message}`);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
const pdfUint8Array = await doc.save();
|
32
|
-
return pdfUint8Array.buffer.slice(pdfUint8Array.byteOffset, pdfUint8Array.byteOffset + pdfUint8Array.byteLength);
|
33
|
-
}
|
34
|
-
catch (error) {
|
35
|
-
throw new Error(`[@pdfme/converter] img2pdf failed: ${error.message}`);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
exports.img2pdf = img2pdf;
|
39
|
-
//# sourceMappingURL=img2pdf.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"img2pdf.js","sourceRoot":"","sources":["../../../src/img2pdf.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAQtC,KAAK,UAAU,OAAO,CAC3B,IAAmB,EACnB,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AM,IAAI,KAAK,CAAC,sCAAuC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;KACnF;AACH,CAAC;AAtCD,0BAsCC"}
|
package/dist/esm/src/img2pdf.js
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import { PDFDocument } from '@pdfme/pdf-lib';
|
2
|
-
export async function img2pdf(imgs, options = {}) {
|
3
|
-
try {
|
4
|
-
const { scale = 1 } = options;
|
5
|
-
if (!Array.isArray(imgs) || imgs.length === 0) {
|
6
|
-
throw new Error('Input must be a non-empty array of image buffers');
|
7
|
-
}
|
8
|
-
const doc = await PDFDocument.create();
|
9
|
-
for (const img of imgs) {
|
10
|
-
try {
|
11
|
-
const image = await doc.embedJpg(img).catch(async () => {
|
12
|
-
return await doc.embedPng(img);
|
13
|
-
});
|
14
|
-
const page = doc.addPage();
|
15
|
-
const { width, height } = image.scale(scale);
|
16
|
-
page.setSize(width, height);
|
17
|
-
page.drawImage(image, {
|
18
|
-
x: 0,
|
19
|
-
y: 0,
|
20
|
-
width,
|
21
|
-
height,
|
22
|
-
});
|
23
|
-
}
|
24
|
-
catch (error) {
|
25
|
-
throw new Error(`Failed to process image: ${error.message}`);
|
26
|
-
}
|
27
|
-
}
|
28
|
-
const pdfUint8Array = await doc.save();
|
29
|
-
return pdfUint8Array.buffer.slice(pdfUint8Array.byteOffset, pdfUint8Array.byteOffset + pdfUint8Array.byteLength);
|
30
|
-
}
|
31
|
-
catch (error) {
|
32
|
-
throw new Error(`[@pdfme/converter] img2pdf failed: ${error.message}`);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
//# sourceMappingURL=img2pdf.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"img2pdf.js","sourceRoot":"","sources":["../../../src/img2pdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAQ7C,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,IAAmB,EACnB,UAA0B,EAAE;I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CAAC,sCAAuC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;KACnF;AACH,CAAC"}
|
package/src/img2pdf.ts
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
import { PDFDocument } from '@pdfme/pdf-lib';
|
2
|
-
import type { ImageType } from './types.js';
|
3
|
-
|
4
|
-
export interface Img2PdfOptions {
|
5
|
-
scale?: number;
|
6
|
-
imageType?: ImageType;
|
7
|
-
}
|
8
|
-
|
9
|
-
export async function img2pdf(
|
10
|
-
imgs: ArrayBuffer[],
|
11
|
-
options: Img2PdfOptions = {}
|
12
|
-
): Promise<ArrayBuffer> {
|
13
|
-
try {
|
14
|
-
const { scale = 1 } = options;
|
15
|
-
|
16
|
-
if (!Array.isArray(imgs) || imgs.length === 0) {
|
17
|
-
throw new Error('Input must be a non-empty array of image buffers');
|
18
|
-
}
|
19
|
-
|
20
|
-
const doc = await PDFDocument.create();
|
21
|
-
for (const img of imgs) {
|
22
|
-
try {
|
23
|
-
const image = await doc.embedJpg(img).catch(async () => {
|
24
|
-
return await doc.embedPng(img);
|
25
|
-
});
|
26
|
-
const page = doc.addPage();
|
27
|
-
const { width, height } = image.scale(scale);
|
28
|
-
page.setSize(width, height);
|
29
|
-
page.drawImage(image, {
|
30
|
-
x: 0,
|
31
|
-
y: 0,
|
32
|
-
width,
|
33
|
-
height,
|
34
|
-
});
|
35
|
-
} catch (error) {
|
36
|
-
throw new Error(`Failed to process image: ${(error as Error).message}`);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
const pdfUint8Array = await doc.save();
|
40
|
-
return pdfUint8Array.buffer.slice(
|
41
|
-
pdfUint8Array.byteOffset,
|
42
|
-
pdfUint8Array.byteOffset + pdfUint8Array.byteLength
|
43
|
-
);
|
44
|
-
} catch (error) {
|
45
|
-
throw new Error(`[@pdfme/converter] img2pdf failed: ${(error as Error).message}`);
|
46
|
-
}
|
47
|
-
}
|
package/src/types.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export type ImageType = 'jpeg' | 'png';
|