@pdfme/generator 3.4.3 → 4.0.0-dev.3
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__/generate.test.js +9 -0
- package/dist/cjs/__tests__/generate.test.js.map +1 -1
- package/dist/cjs/__tests__/integration1.test.js +2 -1
- package/dist/cjs/__tests__/integration1.test.js.map +1 -1
- package/dist/cjs/__tests__/integration2.test.js +2 -1
- package/dist/cjs/__tests__/integration2.test.js.map +1 -1
- package/dist/cjs/__tests__/integration3.test.js +2 -1
- package/dist/cjs/__tests__/integration3.test.js.map +1 -1
- package/dist/cjs/__tests__/integration4.test.js +2 -1
- package/dist/cjs/__tests__/integration4.test.js.map +1 -1
- package/dist/cjs/src/generate.js +29 -14
- package/dist/cjs/src/generate.js.map +1 -1
- package/dist/cjs/src/helper.js +55 -41
- package/dist/cjs/src/helper.js.map +1 -1
- package/dist/esm/__tests__/generate.test.js +9 -0
- package/dist/esm/__tests__/generate.test.js.map +1 -1
- package/dist/esm/__tests__/integration1.test.js +2 -1
- package/dist/esm/__tests__/integration1.test.js.map +1 -1
- package/dist/esm/__tests__/integration2.test.js +2 -1
- package/dist/esm/__tests__/integration2.test.js.map +1 -1
- package/dist/esm/__tests__/integration3.test.js +2 -1
- package/dist/esm/__tests__/integration3.test.js.map +1 -1
- package/dist/esm/__tests__/integration4.test.js +2 -1
- package/dist/esm/__tests__/integration4.test.js.map +1 -1
- package/dist/esm/src/generate.js +31 -16
- package/dist/esm/src/generate.js.map +1 -1
- package/dist/esm/src/helper.js +53 -39
- package/dist/esm/src/helper.js.map +1 -1
- package/dist/types/__tests__/assets/templates/index.d.ts +2656 -406
- package/dist/types/src/helper.d.ts +11 -17
- package/package.json +1 -1
- package/src/generate.ts +32 -19
- package/src/helper.ts +74 -64
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"integration1.test.js","sourceRoot":"","sources":["../../../__tests__/integration1.test.ts"],"names":[],"mappings":"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EAAE;oBACxB,OAAO,EAAE,EAAE,IAAI,EAAE;iBAClB,CAAC,CAAC;gBAEH,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACtC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC;gBACrD,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE;oBAClB,MAAM,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;iBACzD;qBAAM,IAAI,WAAW,IAAI,qBAAqB,EAAE;oBAC/C,OAAO,CAAC,IAAI,CAAC,+BAA+B,GAAG,OAAO,WAAW,6CAA6C,qBAAqB,WAAW,CAAC,CAAC;iBACjJ;gBAED,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC;gBAC5C,MAAM,UAAU,GAAG,gBAAgB,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC;gBAElD,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;gBAC5B,MAAM,GAAG,GAAQ,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAC1E,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC;gBACnB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { writeFileSync } from 'fs';
|
2
2
|
import generate from '../src/generate';
|
3
3
|
import { barcode, business } from './assets/templates';
|
4
|
+
import { getInputFromTemplate } from '@pdfme/common';
|
4
5
|
import { text, image, barcodes } from '@pdfme/schemas';
|
5
6
|
import { getFont, getPdf, getPdfTmpPath, getPdfAssertPath } from './utils';
|
6
7
|
const PERFORMANCE_THRESHOLD = parseFloat(process.env.PERFORMANCE_THRESHOLD || '2.0');
|
@@ -11,7 +12,7 @@ describe('generate integration test(barcode, business)', () => {
|
|
11
12
|
const [key, template] = entries[l];
|
12
13
|
// eslint-disable-next-line no-loop-func
|
13
14
|
test(`snapshot ${key}`, async () => {
|
14
|
-
const inputs = template
|
15
|
+
const inputs = getInputFromTemplate(template);
|
15
16
|
const font = getFont();
|
16
17
|
font.SauceHanSansJP.fallback = false;
|
17
18
|
font.SauceHanSerifJP.fallback = false;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"integration2.test.js","sourceRoot":"","sources":["../../../__tests__/integration2.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3E,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,KAAK,CAAC,CAAC;AAErF,QAAQ,CAAC,8CAA8C,EAAE,GAAG,EAAE;IAC5D,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,EAAE;QACxD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EA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MAAM,GAAG,GAAQ,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAC1E,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC;gBACnB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { writeFileSync } from 'fs';
|
2
2
|
import generate from '../src/generate';
|
3
3
|
import { other, shape } from './assets/templates';
|
4
|
+
import { getInputFromTemplate } from '@pdfme/common';
|
4
5
|
import { text, image, line, rectangle, ellipse, readOnlyText, barcodes, readOnlySvg, } from '@pdfme/schemas';
|
5
6
|
import { getFont, getPdf, getPdfTmpPath, getPdfAssertPath } from './utils';
|
6
7
|
const signature = {
|
@@ -22,7 +23,7 @@ describe('generate integration test(other, shape)', () => {
|
|
22
23
|
const [key, template] = entries[l];
|
23
24
|
// eslint-disable-next-line no-loop-func
|
24
25
|
test(`snapshot ${key}`, async () => {
|
25
|
-
const inputs = template
|
26
|
+
const inputs = getInputFromTemplate(template);
|
26
27
|
const font = getFont();
|
27
28
|
font.SauceHanSansJP.fallback = false;
|
28
29
|
font.SauceHanSerifJP.fallback = false;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"integration3.test.js","sourceRoot":"","sources":["../../../__tests__/integration3.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,SAAS,EACT,OA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GAAQ,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAC1E,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC;gBACnB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { writeFileSync } from 'fs';
|
2
2
|
import generate from '../src/generate';
|
3
3
|
import { textType } from './assets/templates';
|
4
|
+
import { getInputFromTemplate } from "@pdfme/common";
|
4
5
|
import { text, image, barcodes } from '@pdfme/schemas';
|
5
6
|
import { getFont, getPdf, getPdfTmpPath, getPdfAssertPath } from './utils';
|
6
7
|
const PERFORMANCE_THRESHOLD = parseFloat(process.env.PERFORMANCE_THRESHOLD || '2.5');
|
@@ -11,7 +12,7 @@ describe('generate integration test(slower)', () => {
|
|
11
12
|
const [key, template] = entries[l];
|
12
13
|
// eslint-disable-next-line no-loop-func
|
13
14
|
test(`snapshot ${key}`, async () => {
|
14
|
-
const inputs = template
|
15
|
+
const inputs = getInputFromTemplate(template);
|
15
16
|
const font = getFont();
|
16
17
|
font.SauceHanSansJP.fallback = false;
|
17
18
|
font.SauceHanSerifJP.fallback = false;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"integration4.test.js","sourceRoot":"","sources":["../../../__tests__/integration4.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,C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,UAAU,CAAC;gBACrD,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE;oBAClB,MAAM,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;iBACzD;qBAAM,IAAI,WAAW,IAAI,qBAAqB,EAAE;oBAC/C,OAAO,CAAC,IAAI,CAAC,+BAA+B,GAAG,OAAO,WAAW,6CAA6C,qBAAqB,WAAW,CAAC,CAAC;iBACjJ;gBAED,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC;gBAC5C,MAAM,UAAU,GAAG,gBAAgB,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC;gBAElD,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;gBAC5B,MAAM,GAAG,GAAQ,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAC1E,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC;gBACnB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/esm/src/generate.js
CHANGED
@@ -1,29 +1,44 @@
|
|
1
1
|
import * as pdfLib from '@pdfme/pdf-lib';
|
2
|
-
import { checkGenerateProps } from '@pdfme/common';
|
3
|
-
import {
|
2
|
+
import { checkGenerateProps, getDynamicTemplate } from '@pdfme/common';
|
3
|
+
import { modifyTemplateForTable, getDynamicHeightForTable } from '@pdfme/schemas';
|
4
|
+
import { insertPage, preprocessing, postProcessing, getEmbedPdfPages } from './helper.js';
|
4
5
|
const generate = async (props) => {
|
5
6
|
checkGenerateProps(props);
|
6
7
|
const { inputs, template, options = {}, plugins: userPlugins = {} } = props;
|
8
|
+
const basePdf = template.basePdf;
|
7
9
|
if (inputs.length === 0) {
|
8
10
|
throw new Error('inputs should not be empty');
|
9
11
|
}
|
10
|
-
const { pdfDoc,
|
11
|
-
const keys = readOnlySchemaKeys.concat(Object.keys(inputs[0]));
|
12
|
-
if (template.columns) {
|
13
|
-
keys.sort((a, b) => (template.columns ?? []).indexOf(a) - (template.columns ?? []).indexOf(b));
|
14
|
-
}
|
12
|
+
const { pdfDoc, renderObj } = await preprocessing({ template, userPlugins });
|
15
13
|
const _cache = new Map();
|
16
14
|
for (let i = 0; i < inputs.length; i += 1) {
|
17
|
-
const
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
const input = inputs[i];
|
16
|
+
const dynamicTemplate = await getDynamicTemplate({
|
17
|
+
template,
|
18
|
+
input,
|
19
|
+
options,
|
20
|
+
_cache,
|
21
|
+
modifyTemplate: (arg) => {
|
22
|
+
return modifyTemplateForTable(arg);
|
23
|
+
},
|
24
|
+
getDynamicHeight: (value, args) => {
|
25
|
+
if (args.schema.type !== 'table')
|
26
|
+
return Promise.resolve(args.schema.height);
|
27
|
+
return getDynamicHeightForTable(value, args);
|
28
|
+
},
|
29
|
+
});
|
30
|
+
const { basePages, embedPdfBoxes } = await getEmbedPdfPages({
|
31
|
+
template: dynamicTemplate,
|
32
|
+
pdfDoc,
|
33
|
+
});
|
34
|
+
const keys = dynamicTemplate.schemas.flatMap((schemaObj) => Object.keys(schemaObj));
|
35
|
+
for (let j = 0; j < basePages.length; j += 1) {
|
36
|
+
const basePage = basePages[j];
|
21
37
|
const embedPdfBox = embedPdfBoxes[j];
|
22
|
-
const page =
|
23
|
-
drawEmbeddedPage({ page, embeddedPage, embedPdfBox });
|
38
|
+
const page = insertPage({ basePage, embedPdfBox, pdfDoc });
|
24
39
|
for (let l = 0; l < keys.length; l += 1) {
|
25
40
|
const key = keys[l];
|
26
|
-
const schemaObj =
|
41
|
+
const schemaObj = dynamicTemplate.schemas[j] || {};
|
27
42
|
const schema = schemaObj[key];
|
28
43
|
if (!schema) {
|
29
44
|
continue;
|
@@ -32,8 +47,8 @@ const generate = async (props) => {
|
|
32
47
|
if (!render) {
|
33
48
|
continue;
|
34
49
|
}
|
35
|
-
const value = schema.readOnly ? schema.
|
36
|
-
await render({ key, value, schema, pdfLib, pdfDoc, page, options, _cache });
|
50
|
+
const value = schema.readOnly ? schema.content || '' : input[key];
|
51
|
+
await render({ key, value, schema, basePdf, pdfLib, pdfDoc, page, options, _cache });
|
37
52
|
}
|
38
53
|
}
|
39
54
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1F,MAAM,QAAQ,GAAG,KAAK,EAAE,KAAoB,EAAE,EAAE;IAC9C,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;IAC5E,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IAEjC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KAC/C;IAED,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AAC,CAAC,CAAC,CAAC;YACrC,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;gBACvC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACpB,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACnD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;gBAC9B,IAAI,CAAC,MAAM,EAAE;oBACX,SAAS;iBACV;gBAED,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACtC,IAAI,CAAC,MAAM,EAAE;oBACX,SAAS;iBACV;gBACD,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClE,MAAM,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;aACtF;SACF;KACF;IAED,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAEpC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/esm/src/helper.js
CHANGED
@@ -1,45 +1,51 @@
|
|
1
1
|
import * as fontkit from 'fontkit';
|
2
|
-
import
|
2
|
+
import { getB64BasePdf, isBlankPdf, mm2pt, } from '@pdfme/common';
|
3
3
|
import { builtInPlugins } from '@pdfme/schemas';
|
4
|
-
import { PDFDocument } from '@pdfme/pdf-lib';
|
5
|
-
import { getB64BasePdf } from '@pdfme/common';
|
4
|
+
import { PDFPage, PDFDocument, PDFEmbeddedPage } from '@pdfme/pdf-lib';
|
6
5
|
import { TOOL_NAME } from './constants.js';
|
7
|
-
export const
|
8
|
-
const {
|
9
|
-
let
|
6
|
+
export const getEmbedPdfPages = async (arg) => {
|
7
|
+
const { template: { schemas, basePdf }, pdfDoc, } = arg;
|
8
|
+
let basePages = [];
|
10
9
|
let embedPdfBoxes = [];
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
10
|
+
if (isBlankPdf(basePdf)) {
|
11
|
+
const { width: _width, height: _height } = basePdf;
|
12
|
+
const width = mm2pt(_width);
|
13
|
+
const height = mm2pt(_height);
|
14
|
+
basePages = schemas.map(() => {
|
15
|
+
const page = PDFPage.create(pdfDoc);
|
16
|
+
page.setSize(width, height);
|
17
|
+
return page;
|
18
|
+
});
|
19
|
+
embedPdfBoxes = schemas.map(() => ({
|
20
|
+
mediaBox: { x: 0, y: 0, width, height },
|
21
|
+
bleedBox: { x: 0, y: 0, width, height },
|
22
|
+
trimBox: { x: 0, y: 0, width, height },
|
23
|
+
}));
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
const willLoadPdf = typeof basePdf === 'string' ? await getB64BasePdf(basePdf) : basePdf;
|
27
|
+
const embedPdf = await PDFDocument.load(willLoadPdf);
|
28
|
+
const embedPdfPages = embedPdf.getPages();
|
29
|
+
embedPdfBoxes = embedPdfPages.map((p) => ({
|
30
|
+
mediaBox: p.getMediaBox(),
|
31
|
+
bleedBox: p.getBleedBox(),
|
32
|
+
trimBox: p.getTrimBox(),
|
33
|
+
}));
|
34
|
+
const boundingBoxes = embedPdfPages.map((p) => {
|
35
|
+
const { x, y, width, height } = p.getMediaBox();
|
36
|
+
return { left: x, bottom: y, right: width, top: height + y };
|
37
|
+
});
|
38
|
+
const transformationMatrices = embedPdfPages.map(() => [1, 0, 0, 1, 0, 0]);
|
39
|
+
basePages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
|
40
|
+
}
|
41
|
+
return { basePages, embedPdfBoxes };
|
34
42
|
};
|
35
43
|
export const preprocessing = async (arg) => {
|
36
44
|
const { template, userPlugins } = arg;
|
37
|
-
const {
|
38
|
-
const pdfDoc = await
|
45
|
+
const { schemas } = template;
|
46
|
+
const pdfDoc = await PDFDocument.create();
|
39
47
|
// @ts-ignore
|
40
48
|
pdfDoc.registerFontkit(fontkit);
|
41
|
-
const pagesAndBoxes = await getEmbeddedPagesAndEmbedPdfBoxes({ pdfDoc, basePdf });
|
42
|
-
const { embeddedPages, embedPdfBoxes } = pagesAndBoxes;
|
43
49
|
const pluginValues = (Object.values(userPlugins).length > 0
|
44
50
|
? Object.values(userPlugins)
|
45
51
|
: Object.values(builtInPlugins));
|
@@ -52,12 +58,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
52
58
|
}
|
53
59
|
return { ...acc, [type]: render.pdf };
|
54
60
|
}, {});
|
55
|
-
|
56
|
-
const entries = Object.entries(schema);
|
57
|
-
const keys = entries.reduce((acc, [key, value]) => (value.readOnly ? [...acc, key] : acc), []);
|
58
|
-
return [...acc, ...keys];
|
59
|
-
}, []);
|
60
|
-
return { pdfDoc, embeddedPages, embedPdfBoxes, renderObj, readOnlySchemaKeys };
|
61
|
+
return { pdfDoc, renderObj };
|
61
62
|
};
|
62
63
|
export const postProcessing = (props) => {
|
63
64
|
const { pdfDoc, options } = props;
|
@@ -72,4 +73,17 @@ export const postProcessing = (props) => {
|
|
72
73
|
pdfDoc.setSubject(subject);
|
73
74
|
pdfDoc.setTitle(title);
|
74
75
|
};
|
76
|
+
export const insertPage = (arg) => {
|
77
|
+
const { basePage, embedPdfBox, pdfDoc } = arg;
|
78
|
+
const size = basePage instanceof PDFEmbeddedPage ? basePage.size() : basePage.getSize();
|
79
|
+
const insertedPage = pdfDoc.addPage([size.width, size.height]);
|
80
|
+
if (basePage instanceof PDFEmbeddedPage) {
|
81
|
+
insertedPage.drawPage(basePage);
|
82
|
+
const { mediaBox, bleedBox, trimBox } = embedPdfBox;
|
83
|
+
insertedPage.setMediaBox(mediaBox.x, mediaBox.y, mediaBox.width, mediaBox.height);
|
84
|
+
insertedPage.setBleedBox(bleedBox.x, bleedBox.y, bleedBox.width, bleedBox.height);
|
85
|
+
insertedPage.setTrimBox(trimBox.x, trimBox.y, trimBox.width, trimBox.height);
|
86
|
+
}
|
87
|
+
return insertedPage;
|
88
|
+
};
|
75
89
|
//# sourceMappingURL=helper.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAOL,aAAa,EACb,UAAU,EACV,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAwB,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,GAAgD,EAAE,EAAE;IACzF,MAAM,EACJ,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAC9B,MAAM,GACP,GAAG,GAAG,CAAC;IACR,IAAI,SAAS,GAAkC,EAAE,CAAC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