@pdfme/generator 3.1.1-dev.5 → 3.1.1-dev.6

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.
@@ -9,7 +9,7 @@ const templates_1 = require("./assets/templates");
9
9
  const schemas_1 = require("@pdfme/schemas");
10
10
  const utils_1 = require("./utils");
11
11
  describe('generate integration test(label, envelope)', () => {
12
- describe.each([templates_1.label, templates_1.envelope])('%i', (templateData) => {
12
+ describe.each([templates_1.label, templates_1.envelope])('%s', (templateData) => {
13
13
  const entries = Object.entries(templateData);
14
14
  for (let l = 0; l < entries.length; l += 1) {
15
15
  const [key, template] = entries[l];
@@ -9,7 +9,7 @@ const templates_1 = require("./assets/templates");
9
9
  const schemas_1 = require("@pdfme/schemas");
10
10
  const utils_1 = require("./utils");
11
11
  describe('generate integration test(barcode, business)', () => {
12
- describe.each([templates_1.barcode, templates_1.business])('%i', (templateData) => {
12
+ describe.each([templates_1.barcode, templates_1.business])('%s', (templateData) => {
13
13
  const entries = Object.entries(templateData);
14
14
  for (let l = 0; l < entries.length; l += 1) {
15
15
  const [key, template] = entries[l];
@@ -9,7 +9,7 @@ const templates_1 = require("./assets/templates");
9
9
  const schemas_1 = require("@pdfme/schemas");
10
10
  const utils_1 = require("./utils");
11
11
  describe('generate integration test(textType, other)', () => {
12
- describe.each([templates_1.textType, templates_1.other])('%i', (templateData) => {
12
+ describe.each([templates_1.textType, templates_1.other])('%s', (templateData) => {
13
13
  const entries = Object.entries(templateData);
14
14
  for (let l = 0; l < entries.length; l += 1) {
15
15
  const [key, template] = entries[l];
@@ -24,38 +24,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const pdfLib = __importStar(require("@pdfme/pdf-lib"));
27
- const fontkit = __importStar(require("fontkit"));
28
27
  const common_1 = require("@pdfme/common");
29
- const schemas_1 = require("@pdfme/schemas");
30
- const pdfUtils_js_1 = require("./pdfUtils.js");
31
- const constants_js_1 = require("./constants.js");
32
- const preprocessing = async ({ template }) => {
33
- const { basePdf } = template;
34
- const pdfDoc = await pdfLib.PDFDocument.create();
35
- // @ts-ignore
36
- pdfDoc.registerFontkit(fontkit);
37
- const pagesAndBoxes = await (0, pdfUtils_js_1.getEmbeddedPagesAndEmbedPdfBoxes)({ pdfDoc, basePdf });
38
- const { embeddedPages, embedPdfBoxes } = pagesAndBoxes;
39
- return { pdfDoc, embeddedPages, embedPdfBoxes };
40
- };
41
- const postProcessing = (props) => {
42
- const { pdfDoc, options } = props;
43
- const { author = constants_js_1.TOOL_NAME, creationDate = new Date(), creator = constants_js_1.TOOL_NAME, keywords = [], language = 'en-US', modificationDate = new Date(), producer = constants_js_1.TOOL_NAME, subject = '', title = '', } = options;
44
- pdfDoc.setAuthor(author);
45
- pdfDoc.setCreationDate(creationDate);
46
- pdfDoc.setCreator(creator);
47
- pdfDoc.setKeywords(keywords);
48
- pdfDoc.setLanguage(language);
49
- pdfDoc.setModificationDate(modificationDate);
50
- pdfDoc.setProducer(producer);
51
- pdfDoc.setSubject(subject);
52
- pdfDoc.setTitle(title);
53
- };
28
+ const helper_js_1 = require("./helper.js");
54
29
  const generate = async (props) => {
55
30
  (0, common_1.checkGenerateProps)(props);
56
31
  const { inputs, template, options = {}, plugins: userPlugins = {} } = props;
57
- const { pdfDoc, embeddedPages, embedPdfBoxes } = await preprocessing({ template });
58
- const plugins = Object.values(userPlugins).length > 0 ? userPlugins : schemas_1.builtInPlugins;
32
+ const { pdfDoc, embeddedPages, embedPdfBoxes, renderObj } = await (0, helper_js_1.preprocessing)({
33
+ template,
34
+ userPlugins,
35
+ });
59
36
  const _cache = new Map();
60
37
  for (let i = 0; i < inputs.length; i += 1) {
61
38
  const inputObj = inputs[i];
@@ -65,7 +42,7 @@ const generate = async (props) => {
65
42
  const { width: pageWidth, height: pageHeight } = embeddedPage;
66
43
  const embedPdfBox = embedPdfBoxes[j];
67
44
  const page = pdfDoc.addPage([pageWidth, pageHeight]);
68
- (0, pdfUtils_js_1.drawEmbeddedPage)({ page, embeddedPage, embedPdfBox });
45
+ (0, helper_js_1.drawEmbeddedPage)({ page, embeddedPage, embedPdfBox });
69
46
  for (let l = 0; l < keys.length; l += 1) {
70
47
  const key = keys[l];
71
48
  const schemaObj = template.schemas[j];
@@ -74,16 +51,15 @@ const generate = async (props) => {
74
51
  if (!schema || !value) {
75
52
  continue;
76
53
  }
77
- const render = Object.values(plugins).find((plugin) => plugin.propPanel.defaultSchema.type === schema.type)?.pdf;
54
+ const render = renderObj[schema.type];
78
55
  if (!render) {
79
- throw new Error(`[@pdfme/generator] Renderer for type ${schema.type} not found.
80
- Check this document: https://pdfme.com/docs/custom-schemas`);
56
+ continue;
81
57
  }
82
58
  await render({ value, schema, pdfLib, pdfDoc, page, options, _cache });
83
59
  }
84
60
  }
85
61
  }
86
- postProcessing({ pdfDoc, options });
62
+ (0, helper_js_1.postProcessing)({ pdfDoc, options });
87
63
  return pdfDoc.save();
88
64
  };
89
65
  exports.default = generate;
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;AACzC,iDAAmC;AAEnC,0CAAmD;AACnD,4CAAgD;AAChD,+CAAmF;AACnF,iDAA2C;AAE3C,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,QAAQ,EAA0B,EAAE,EAAE;IACnE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAE7B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IACjD,aAAa;IACb,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAEhC,MAAM,aAAa,GAAG,MAAM,IAAA,8CAAgC,EAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAClF,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG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AC,MAAM,EAAE;oBACX,SAAS;iBACV;gBAED,MAAM,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;aACxE;SACF;KACF;IAED,IAAA,0BAAc,EAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAEpC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.postProcessing = exports.preprocessing = exports.drawEmbeddedPage = exports.getEmbeddedPagesAndEmbedPdfBoxes = void 0;
27
+ const fontkit = __importStar(require("fontkit"));
28
+ const pdfLib = __importStar(require("@pdfme/pdf-lib"));
29
+ const schemas_1 = require("@pdfme/schemas");
30
+ const pdf_lib_1 = require("@pdfme/pdf-lib");
31
+ const common_1 = require("@pdfme/common");
32
+ const constants_js_1 = require("./constants.js");
33
+ const getEmbeddedPagesAndEmbedPdfBoxes = async (arg) => {
34
+ const { pdfDoc, basePdf } = arg;
35
+ let embeddedPages = [];
36
+ let embedPdfBoxes = [];
37
+ const willLoadPdf = typeof basePdf === 'string' ? await (0, common_1.getB64BasePdf)(basePdf) : basePdf;
38
+ const embedPdf = await pdf_lib_1.PDFDocument.load(willLoadPdf);
39
+ const embedPdfPages = embedPdf.getPages();
40
+ embedPdfBoxes = embedPdfPages.map((p) => ({
41
+ mediaBox: p.getMediaBox(),
42
+ bleedBox: p.getBleedBox(),
43
+ trimBox: p.getTrimBox(),
44
+ }));
45
+ const boundingBoxes = embedPdfPages.map((p) => {
46
+ const { x, y, width, height } = p.getMediaBox();
47
+ return { left: x, bottom: y, right: width, top: height + y };
48
+ });
49
+ const transformationMatrices = embedPdfPages.map(() => [1, 0, 0, 1, 0, 0]);
50
+ embeddedPages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
51
+ return { embeddedPages, embedPdfBoxes };
52
+ };
53
+ exports.getEmbeddedPagesAndEmbedPdfBoxes = getEmbeddedPagesAndEmbedPdfBoxes;
54
+ const drawEmbeddedPage = (arg) => {
55
+ const { page, embeddedPage, embedPdfBox } = arg;
56
+ page.drawPage(embeddedPage);
57
+ const { mediaBox: mb, bleedBox: bb, trimBox: tb } = embedPdfBox;
58
+ page.setMediaBox(mb.x, mb.y, mb.width, mb.height);
59
+ page.setBleedBox(bb.x, bb.y, bb.width, bb.height);
60
+ page.setTrimBox(tb.x, tb.y, tb.width, tb.height);
61
+ };
62
+ exports.drawEmbeddedPage = drawEmbeddedPage;
63
+ const preprocessing = async (arg) => {
64
+ const { template, userPlugins } = arg;
65
+ const { basePdf } = template;
66
+ const pdfDoc = await pdfLib.PDFDocument.create();
67
+ // @ts-ignore
68
+ pdfDoc.registerFontkit(fontkit);
69
+ const pagesAndBoxes = await (0, exports.getEmbeddedPagesAndEmbedPdfBoxes)({ pdfDoc, basePdf });
70
+ const { embeddedPages, embedPdfBoxes } = pagesAndBoxes;
71
+ const pluginValues = (Object.values(userPlugins).length > 0
72
+ ? Object.values(userPlugins)
73
+ : Object.values(schemas_1.builtInPlugins));
74
+ const schemaTypes = template.schemas.flatMap((schemaObj) => Object.values(schemaObj).map((schema) => schema.type));
75
+ const renderObj = schemaTypes.reduce((acc, type) => {
76
+ const render = pluginValues.find((pv) => pv.propPanel.defaultSchema.type === type);
77
+ if (!render) {
78
+ throw new Error(`[@pdfme/generator] Renderer for type ${type} not found.
79
+ Check this document: https://pdfme.com/docs/custom-schemas`);
80
+ }
81
+ return { ...acc, [type]: render.pdf };
82
+ }, {});
83
+ return { pdfDoc, embeddedPages, embedPdfBoxes, renderObj };
84
+ };
85
+ exports.preprocessing = preprocessing;
86
+ const postProcessing = (props) => {
87
+ const { pdfDoc, options } = props;
88
+ const { author = constants_js_1.TOOL_NAME, creationDate = new Date(), creator = constants_js_1.TOOL_NAME, keywords = [], language = 'en-US', modificationDate = new Date(), producer = constants_js_1.TOOL_NAME, subject = '', title = '', } = options;
89
+ pdfDoc.setAuthor(author);
90
+ pdfDoc.setCreationDate(creationDate);
91
+ pdfDoc.setCreator(creator);
92
+ pdfDoc.setKeywords(keywords);
93
+ pdfDoc.setLanguage(language);
94
+ pdfDoc.setModificationDate(modificationDate);
95
+ pdfDoc.setProducer(producer);
96
+ pdfDoc.setSubject(subject);
97
+ pdfDoc.setTitle(title);
98
+ };
99
+ exports.postProcessing = postProcessing;
100
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,uDAAyC;AAGzC,4CAAgD;AAChD,4CAA6F;AAC7F,0CAAuD;AACvD,iDAA2C;AAGpC,MAAM,gCAAgC,GAAG,KAAK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AI,IAAI,EAAE,EACzB,OAAO,GAAG,wBAAS,EACnB,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,OAAO,EAClB,gBAAgB,GAAG,IAAI,IAAI,EAAE,EAC7B,QAAQ,GAAG,wBAAS,EACpB,OAAO,GAAG,EAAE,EACZ,KAAK,GAAG,EAAE,GACX,GAAG,OAAO,CAAC;IACZ,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IACrC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3B,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3B,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC,CAAC;AAzBW,QAAA,cAAc,kBAyBzB"}
@@ -4,7 +4,7 @@ import { label, envelope } from './assets/templates';
4
4
  import { text, image } from '@pdfme/schemas';
5
5
  import { getFont, getPdf, getPdfTmpPath, getPdfAssertPath } from './utils';
6
6
  describe('generate integration test(label, envelope)', () => {
7
- describe.each([label, envelope])('%i', (templateData) => {
7
+ describe.each([label, envelope])('%s', (templateData) => {
8
8
  const entries = Object.entries(templateData);
9
9
  for (let l = 0; l < entries.length; l += 1) {
10
10
  const [key, template] = entries[l];
@@ -4,7 +4,7 @@ import { barcode, business } from './assets/templates';
4
4
  import { text, image, barcodes } from '@pdfme/schemas';
5
5
  import { getFont, getPdf, getPdfTmpPath, getPdfAssertPath } from './utils';
6
6
  describe('generate integration test(barcode, business)', () => {
7
- describe.each([barcode, business])('%i', (templateData) => {
7
+ describe.each([barcode, business])('%s', (templateData) => {
8
8
  const entries = Object.entries(templateData);
9
9
  for (let l = 0; l < entries.length; l += 1) {
10
10
  const [key, template] = entries[l];
@@ -4,7 +4,7 @@ import { textType, other } from './assets/templates';
4
4
  import { text, image } from '@pdfme/schemas';
5
5
  import { getFont, getPdf, getPdfTmpPath, getPdfAssertPath } from './utils';
6
6
  describe('generate integration test(textType, other)', () => {
7
- describe.each([textType, other])('%i', (templateData) => {
7
+ describe.each([textType, other])('%s', (templateData) => {
8
8
  const entries = Object.entries(templateData);
9
9
  for (let l = 0; l < entries.length; l += 1) {
10
10
  const [key, template] = entries[l];
@@ -1,36 +1,13 @@
1
1
  import * as pdfLib from '@pdfme/pdf-lib';
2
- import * as fontkit from 'fontkit';
3
2
  import { checkGenerateProps } from '@pdfme/common';
4
- import { builtInPlugins } from '@pdfme/schemas';
5
- import { drawEmbeddedPage, getEmbeddedPagesAndEmbedPdfBoxes } from './pdfUtils.js';
6
- import { TOOL_NAME } from './constants.js';
7
- const preprocessing = async ({ template }) => {
8
- const { basePdf } = template;
9
- const pdfDoc = await pdfLib.PDFDocument.create();
10
- // @ts-ignore
11
- pdfDoc.registerFontkit(fontkit);
12
- const pagesAndBoxes = await getEmbeddedPagesAndEmbedPdfBoxes({ pdfDoc, basePdf });
13
- const { embeddedPages, embedPdfBoxes } = pagesAndBoxes;
14
- return { pdfDoc, embeddedPages, embedPdfBoxes };
15
- };
16
- const postProcessing = (props) => {
17
- const { pdfDoc, options } = props;
18
- const { author = TOOL_NAME, creationDate = new Date(), creator = TOOL_NAME, keywords = [], language = 'en-US', modificationDate = new Date(), producer = TOOL_NAME, subject = '', title = '', } = options;
19
- pdfDoc.setAuthor(author);
20
- pdfDoc.setCreationDate(creationDate);
21
- pdfDoc.setCreator(creator);
22
- pdfDoc.setKeywords(keywords);
23
- pdfDoc.setLanguage(language);
24
- pdfDoc.setModificationDate(modificationDate);
25
- pdfDoc.setProducer(producer);
26
- pdfDoc.setSubject(subject);
27
- pdfDoc.setTitle(title);
28
- };
3
+ import { drawEmbeddedPage, preprocessing, postProcessing } from './helper.js';
29
4
  const generate = async (props) => {
30
5
  checkGenerateProps(props);
31
6
  const { inputs, template, options = {}, plugins: userPlugins = {} } = props;
32
- const { pdfDoc, embeddedPages, embedPdfBoxes } = await preprocessing({ template });
33
- const plugins = Object.values(userPlugins).length > 0 ? userPlugins : builtInPlugins;
7
+ const { pdfDoc, embeddedPages, embedPdfBoxes, renderObj } = await preprocessing({
8
+ template,
9
+ userPlugins,
10
+ });
34
11
  const _cache = new Map();
35
12
  for (let i = 0; i < inputs.length; i += 1) {
36
13
  const inputObj = inputs[i];
@@ -49,10 +26,9 @@ const generate = async (props) => {
49
26
  if (!schema || !value) {
50
27
  continue;
51
28
  }
52
- const render = Object.values(plugins).find((plugin) => plugin.propPanel.defaultSchema.type === schema.type)?.pdf;
29
+ const render = renderObj[schema.type];
53
30
  if (!render) {
54
- throw new Error(`[@pdfme/generator] Renderer for type ${schema.type} not found.
55
- Check this document: https://pdfme.com/docs/custom-schemas`);
31
+ continue;
56
32
  }
57
33
  await render({ value, schema, pdfLib, pdfDoc, page, options, _cache });
58
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,QAAQ,EAA0B,EAAE,EAAE;IACnE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAE7B,MAAM,MAAM,GAAG,MA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AAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACtC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;gBAC9B,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAE5B,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE;oBACrB,SAAS;iBACV;gBAED,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACtC,IAAI,CAAC,MAAM,EAAE;oBACX,SAAS;iBACV;gBAED,MAAM,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;aACxE;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"}
@@ -0,0 +1,70 @@
1
+ import * as fontkit from 'fontkit';
2
+ import * as pdfLib from '@pdfme/pdf-lib';
3
+ import { builtInPlugins } from '@pdfme/schemas';
4
+ import { PDFDocument } from '@pdfme/pdf-lib';
5
+ import { getB64BasePdf } from '@pdfme/common';
6
+ import { TOOL_NAME } from './constants.js';
7
+ export const getEmbeddedPagesAndEmbedPdfBoxes = async (arg) => {
8
+ const { pdfDoc, basePdf } = arg;
9
+ let embeddedPages = [];
10
+ let embedPdfBoxes = [];
11
+ const willLoadPdf = typeof basePdf === 'string' ? await getB64BasePdf(basePdf) : basePdf;
12
+ const embedPdf = await PDFDocument.load(willLoadPdf);
13
+ const embedPdfPages = embedPdf.getPages();
14
+ embedPdfBoxes = embedPdfPages.map((p) => ({
15
+ mediaBox: p.getMediaBox(),
16
+ bleedBox: p.getBleedBox(),
17
+ trimBox: p.getTrimBox(),
18
+ }));
19
+ const boundingBoxes = embedPdfPages.map((p) => {
20
+ const { x, y, width, height } = p.getMediaBox();
21
+ return { left: x, bottom: y, right: width, top: height + y };
22
+ });
23
+ const transformationMatrices = embedPdfPages.map(() => [1, 0, 0, 1, 0, 0]);
24
+ embeddedPages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
25
+ return { embeddedPages, embedPdfBoxes };
26
+ };
27
+ export const drawEmbeddedPage = (arg) => {
28
+ const { page, embeddedPage, embedPdfBox } = arg;
29
+ page.drawPage(embeddedPage);
30
+ const { mediaBox: mb, bleedBox: bb, trimBox: tb } = embedPdfBox;
31
+ page.setMediaBox(mb.x, mb.y, mb.width, mb.height);
32
+ page.setBleedBox(bb.x, bb.y, bb.width, bb.height);
33
+ page.setTrimBox(tb.x, tb.y, tb.width, tb.height);
34
+ };
35
+ export const preprocessing = async (arg) => {
36
+ const { template, userPlugins } = arg;
37
+ const { basePdf } = template;
38
+ const pdfDoc = await pdfLib.PDFDocument.create();
39
+ // @ts-ignore
40
+ pdfDoc.registerFontkit(fontkit);
41
+ const pagesAndBoxes = await getEmbeddedPagesAndEmbedPdfBoxes({ pdfDoc, basePdf });
42
+ const { embeddedPages, embedPdfBoxes } = pagesAndBoxes;
43
+ const pluginValues = (Object.values(userPlugins).length > 0
44
+ ? Object.values(userPlugins)
45
+ : Object.values(builtInPlugins));
46
+ const schemaTypes = template.schemas.flatMap((schemaObj) => Object.values(schemaObj).map((schema) => schema.type));
47
+ const renderObj = schemaTypes.reduce((acc, type) => {
48
+ const render = pluginValues.find((pv) => pv.propPanel.defaultSchema.type === type);
49
+ if (!render) {
50
+ throw new Error(`[@pdfme/generator] Renderer for type ${type} not found.
51
+ Check this document: https://pdfme.com/docs/custom-schemas`);
52
+ }
53
+ return { ...acc, [type]: render.pdf };
54
+ }, {});
55
+ return { pdfDoc, embeddedPages, embedPdfBoxes, renderObj };
56
+ };
57
+ export const postProcessing = (props) => {
58
+ const { pdfDoc, options } = props;
59
+ const { author = TOOL_NAME, creationDate = new Date(), creator = TOOL_NAME, keywords = [], language = 'en-US', modificationDate = new Date(), producer = TOOL_NAME, subject = '', title = '', } = options;
60
+ pdfDoc.setAuthor(author);
61
+ pdfDoc.setCreationDate(creationDate);
62
+ pdfDoc.setCreator(creator);
63
+ pdfDoc.setKeywords(keywords);
64
+ pdfDoc.setLanguage(language);
65
+ pdfDoc.setModificationDate(modificationDate);
66
+ pdfDoc.setProducer(producer);
67
+ pdfDoc.setSubject(subject);
68
+ pdfDoc.setTitle(title);
69
+ };
70
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAW,WAAW,EAAyC,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAW,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,EAAE,GAGtD,EAAE,EAAE;IACH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAChC,IAAI,aAAa,GAAsB,EAAE,CAAC;IAC1C,IAAI,aAAa,GAAkB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACzF,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,aAAa,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAE1C,aAAa,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC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AAC;IAC7B,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3B,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import * as pdfLib from '@pdfme/pdf-lib';
2
+ import type { GeneratorOptions, Template, PDFRenderProps } from '@pdfme/common';
3
+ import type { Schema, Plugins } from '@pdfme/common';
4
+ import { PDFPage, PDFDocument, PDFEmbeddedPage } from '@pdfme/pdf-lib';
5
+ import { BasePdf } from '@pdfme/common';
6
+ import type { EmbedPdfBox } from './types';
7
+ export declare const getEmbeddedPagesAndEmbedPdfBoxes: (arg: {
8
+ pdfDoc: PDFDocument;
9
+ basePdf: BasePdf;
10
+ }) => Promise<{
11
+ embeddedPages: pdfLib.PDFEmbeddedPage[];
12
+ embedPdfBoxes: EmbedPdfBox[];
13
+ }>;
14
+ export declare const drawEmbeddedPage: (arg: {
15
+ page: PDFPage;
16
+ embeddedPage: PDFEmbeddedPage;
17
+ embedPdfBox: EmbedPdfBox;
18
+ }) => void;
19
+ export declare const preprocessing: (arg: {
20
+ template: Template;
21
+ userPlugins: Plugins;
22
+ }) => Promise<{
23
+ pdfDoc: pdfLib.PDFDocument;
24
+ embeddedPages: pdfLib.PDFEmbeddedPage[];
25
+ embedPdfBoxes: EmbedPdfBox[];
26
+ renderObj: Record<string, (arg: PDFRenderProps<Schema>) => Promise<void>>;
27
+ }>;
28
+ export declare const postProcessing: (props: {
29
+ pdfDoc: pdfLib.PDFDocument;
30
+ options: GeneratorOptions;
31
+ }) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/generator",
3
- "version": "3.1.1-dev.5",
3
+ "version": "3.1.1-dev.6",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
package/src/generate.ts CHANGED
@@ -1,55 +1,16 @@
1
1
  import * as pdfLib from '@pdfme/pdf-lib';
2
- import * as fontkit from 'fontkit';
3
- import type { GenerateProps, GeneratorOptions, Template } from '@pdfme/common';
2
+ import type { GenerateProps } from '@pdfme/common';
4
3
  import { checkGenerateProps } from '@pdfme/common';
5
- import { builtInPlugins } from '@pdfme/schemas';
6
- import { drawEmbeddedPage, getEmbeddedPagesAndEmbedPdfBoxes } from './pdfUtils.js';
7
- import { TOOL_NAME } from './constants.js';
8
-
9
- const preprocessing = async ({ template }: { template: Template }) => {
10
- const { basePdf } = template;
11
-
12
- const pdfDoc = await pdfLib.PDFDocument.create();
13
- // @ts-ignore
14
- pdfDoc.registerFontkit(fontkit);
15
-
16
- const pagesAndBoxes = await getEmbeddedPagesAndEmbedPdfBoxes({ pdfDoc, basePdf });
17
- const { embeddedPages, embedPdfBoxes } = pagesAndBoxes;
18
-
19
- return { pdfDoc, embeddedPages, embedPdfBoxes };
20
- };
21
-
22
- const postProcessing = (props: { pdfDoc: pdfLib.PDFDocument; options: GeneratorOptions }) => {
23
- const { pdfDoc, options } = props;
24
- const {
25
- author = TOOL_NAME,
26
- creationDate = new Date(),
27
- creator = TOOL_NAME,
28
- keywords = [],
29
- language = 'en-US',
30
- modificationDate = new Date(),
31
- producer = TOOL_NAME,
32
- subject = '',
33
- title = '',
34
- } = options;
35
- pdfDoc.setAuthor(author);
36
- pdfDoc.setCreationDate(creationDate);
37
- pdfDoc.setCreator(creator);
38
- pdfDoc.setKeywords(keywords);
39
- pdfDoc.setLanguage(language);
40
- pdfDoc.setModificationDate(modificationDate);
41
- pdfDoc.setProducer(producer);
42
- pdfDoc.setSubject(subject);
43
- pdfDoc.setTitle(title);
44
- };
4
+ import { drawEmbeddedPage, preprocessing, postProcessing } from './helper.js';
45
5
 
46
6
  const generate = async (props: GenerateProps) => {
47
7
  checkGenerateProps(props);
48
8
  const { inputs, template, options = {}, plugins: userPlugins = {} } = props;
49
9
 
50
- const { pdfDoc, embeddedPages, embedPdfBoxes } = await preprocessing({ template });
51
-
52
- const plugins = Object.values(userPlugins).length > 0 ? userPlugins : builtInPlugins;
10
+ const { pdfDoc, embeddedPages, embedPdfBoxes, renderObj } = await preprocessing({
11
+ template,
12
+ userPlugins,
13
+ });
53
14
 
54
15
  const _cache = new Map();
55
16
 
@@ -74,13 +35,11 @@ const generate = async (props: GenerateProps) => {
74
35
  continue;
75
36
  }
76
37
 
77
- const render = Object.values(plugins).find(
78
- (plugin) => plugin.propPanel.defaultSchema.type === schema.type
79
- )?.pdf;
38
+ const render = renderObj[schema.type];
80
39
  if (!render) {
81
- throw new Error(`[@pdfme/generator] Renderer for type ${schema.type} not found.
82
- Check this document: https://pdfme.com/docs/custom-schemas`);
40
+ continue;
83
41
  }
42
+
84
43
  await render({ value, schema, pdfLib, pdfDoc, page, options, _cache });
85
44
  }
86
45
  }
package/src/helper.ts ADDED
@@ -0,0 +1,115 @@
1
+ import * as fontkit from 'fontkit';
2
+ import * as pdfLib from '@pdfme/pdf-lib';
3
+ import type { GeneratorOptions, Template, PDFRenderProps, Plugin } from '@pdfme/common';
4
+ import type { Schema, Plugins } from '@pdfme/common';
5
+ import { builtInPlugins } from '@pdfme/schemas';
6
+ import { PDFPage, PDFDocument, PDFEmbeddedPage, TransformationMatrix } from '@pdfme/pdf-lib';
7
+ import { getB64BasePdf, BasePdf } from '@pdfme/common';
8
+ import { TOOL_NAME } from './constants.js';
9
+ import type { EmbedPdfBox } from './types';
10
+
11
+ export const getEmbeddedPagesAndEmbedPdfBoxes = async (arg: {
12
+ pdfDoc: PDFDocument;
13
+ basePdf: BasePdf;
14
+ }) => {
15
+ const { pdfDoc, basePdf } = arg;
16
+ let embeddedPages: PDFEmbeddedPage[] = [];
17
+ let embedPdfBoxes: EmbedPdfBox[] = [];
18
+ const willLoadPdf = typeof basePdf === 'string' ? await getB64BasePdf(basePdf) : basePdf;
19
+ const embedPdf = await PDFDocument.load(willLoadPdf);
20
+ const embedPdfPages = embedPdf.getPages();
21
+
22
+ embedPdfBoxes = embedPdfPages.map((p) => ({
23
+ mediaBox: p.getMediaBox(),
24
+ bleedBox: p.getBleedBox(),
25
+ trimBox: p.getTrimBox(),
26
+ }));
27
+
28
+ const boundingBoxes = embedPdfPages.map((p) => {
29
+ const { x, y, width, height } = p.getMediaBox();
30
+
31
+ return { left: x, bottom: y, right: width, top: height + y };
32
+ });
33
+
34
+ const transformationMatrices = embedPdfPages.map(
35
+ () => [1, 0, 0, 1, 0, 0] as TransformationMatrix
36
+ );
37
+
38
+ embeddedPages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
39
+
40
+ return { embeddedPages, embedPdfBoxes };
41
+ };
42
+
43
+ export const drawEmbeddedPage = (arg: {
44
+ page: PDFPage;
45
+ embeddedPage: PDFEmbeddedPage;
46
+ embedPdfBox: EmbedPdfBox;
47
+ }) => {
48
+ const { page, embeddedPage, embedPdfBox } = arg;
49
+ page.drawPage(embeddedPage);
50
+ const { mediaBox: mb, bleedBox: bb, trimBox: tb } = embedPdfBox;
51
+ page.setMediaBox(mb.x, mb.y, mb.width, mb.height);
52
+ page.setBleedBox(bb.x, bb.y, bb.width, bb.height);
53
+ page.setTrimBox(tb.x, tb.y, tb.width, tb.height);
54
+ };
55
+
56
+ export const preprocessing = async (arg: { template: Template; userPlugins: Plugins }) => {
57
+ const { template, userPlugins } = arg;
58
+ const { basePdf } = template;
59
+
60
+ const pdfDoc = await pdfLib.PDFDocument.create();
61
+ // @ts-ignore
62
+ pdfDoc.registerFontkit(fontkit);
63
+
64
+ const pagesAndBoxes = await getEmbeddedPagesAndEmbedPdfBoxes({ pdfDoc, basePdf });
65
+ const { embeddedPages, embedPdfBoxes } = pagesAndBoxes;
66
+
67
+ const pluginValues = (
68
+ Object.values(userPlugins).length > 0
69
+ ? Object.values(userPlugins)
70
+ : Object.values(builtInPlugins)
71
+ ) as Plugin<Schema>[];
72
+
73
+ const schemaTypes = template.schemas.flatMap((schemaObj) =>
74
+ Object.values(schemaObj).map((schema) => schema.type)
75
+ );
76
+
77
+ const renderObj = schemaTypes.reduce((acc, type) => {
78
+ const render = pluginValues.find((pv) => pv.propPanel.defaultSchema.type === type);
79
+
80
+ if (!render) {
81
+ throw new Error(`[@pdfme/generator] Renderer for type ${type} not found.
82
+ Check this document: https://pdfme.com/docs/custom-schemas`);
83
+ }
84
+ return { ...acc, [type]: render.pdf };
85
+ }, {} as Record<string, (arg: PDFRenderProps<Schema>) => Promise<void>>);
86
+
87
+ return { pdfDoc, embeddedPages, embedPdfBoxes, renderObj };
88
+ };
89
+
90
+ export const postProcessing = (props: {
91
+ pdfDoc: pdfLib.PDFDocument;
92
+ options: GeneratorOptions;
93
+ }) => {
94
+ const { pdfDoc, options } = props;
95
+ const {
96
+ author = TOOL_NAME,
97
+ creationDate = new Date(),
98
+ creator = TOOL_NAME,
99
+ keywords = [],
100
+ language = 'en-US',
101
+ modificationDate = new Date(),
102
+ producer = TOOL_NAME,
103
+ subject = '',
104
+ title = '',
105
+ } = options;
106
+ pdfDoc.setAuthor(author);
107
+ pdfDoc.setCreationDate(creationDate);
108
+ pdfDoc.setCreator(creator);
109
+ pdfDoc.setKeywords(keywords);
110
+ pdfDoc.setLanguage(language);
111
+ pdfDoc.setModificationDate(modificationDate);
112
+ pdfDoc.setProducer(producer);
113
+ pdfDoc.setSubject(subject);
114
+ pdfDoc.setTitle(title);
115
+ };
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.drawEmbeddedPage = exports.getEmbeddedPagesAndEmbedPdfBoxes = void 0;
4
- const pdf_lib_1 = require("@pdfme/pdf-lib");
5
- const common_1 = require("@pdfme/common");
6
- const getEmbeddedPagesAndEmbedPdfBoxes = async (arg) => {
7
- const { pdfDoc, basePdf } = arg;
8
- let embeddedPages = [];
9
- let embedPdfBoxes = [];
10
- const willLoadPdf = typeof basePdf === 'string' ? await (0, common_1.getB64BasePdf)(basePdf) : basePdf;
11
- const embedPdf = await pdf_lib_1.PDFDocument.load(willLoadPdf);
12
- const embedPdfPages = embedPdf.getPages();
13
- embedPdfBoxes = embedPdfPages.map((p) => ({
14
- mediaBox: p.getMediaBox(),
15
- bleedBox: p.getBleedBox(),
16
- trimBox: p.getTrimBox(),
17
- }));
18
- const boundingBoxes = embedPdfPages.map((p) => {
19
- const { x, y, width, height } = p.getMediaBox();
20
- return { left: x, bottom: y, right: width, top: height + y };
21
- });
22
- const transformationMatrices = embedPdfPages.map(() => [1, 0, 0, 1, 0, 0]);
23
- embeddedPages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
24
- return { embeddedPages, embedPdfBoxes };
25
- };
26
- exports.getEmbeddedPagesAndEmbedPdfBoxes = getEmbeddedPagesAndEmbedPdfBoxes;
27
- const drawEmbeddedPage = (arg) => {
28
- const { page, embeddedPage, embedPdfBox } = arg;
29
- page.drawPage(embeddedPage);
30
- const { mediaBox: mb, bleedBox: bb, trimBox: tb } = embedPdfBox;
31
- page.setMediaBox(mb.x, mb.y, mb.width, mb.height);
32
- page.setBleedBox(bb.x, bb.y, bb.width, bb.height);
33
- page.setTrimBox(tb.x, tb.y, tb.width, tb.height);
34
- };
35
- exports.drawEmbeddedPage = drawEmbeddedPage;
36
- //# sourceMappingURL=pdfUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pdfUtils.js","sourceRoot":"","sources":["../../../src/pdfUtils.ts"],"names":[],"mappings":";;;AAAA,4CAA6F;AAC7F,0CAAuD;AAGhD,MAAM,gCAAgC,GAAG,KAAK,EAAE,GAGtD,EAAE,EAAE;IACH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAChC,IAAI,aAAa,GAAsB,EAAE,CAAC;IAC1C,IAAI,aAAa,GAAkB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,IAAA,sBAAa,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACzF,MAAM,QAAQ,GAAG,MAAM,qBAAW,CAAC,IAAI,C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AAE,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,WAAW,CAAC;IAChE,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IAClD,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IAClD,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW3B"}
@@ -1,31 +0,0 @@
1
- import { PDFDocument } from '@pdfme/pdf-lib';
2
- import { getB64BasePdf } from '@pdfme/common';
3
- export const getEmbeddedPagesAndEmbedPdfBoxes = async (arg) => {
4
- const { pdfDoc, basePdf } = arg;
5
- let embeddedPages = [];
6
- let embedPdfBoxes = [];
7
- const willLoadPdf = typeof basePdf === 'string' ? await getB64BasePdf(basePdf) : basePdf;
8
- const embedPdf = await PDFDocument.load(willLoadPdf);
9
- const embedPdfPages = embedPdf.getPages();
10
- embedPdfBoxes = embedPdfPages.map((p) => ({
11
- mediaBox: p.getMediaBox(),
12
- bleedBox: p.getBleedBox(),
13
- trimBox: p.getTrimBox(),
14
- }));
15
- const boundingBoxes = embedPdfPages.map((p) => {
16
- const { x, y, width, height } = p.getMediaBox();
17
- return { left: x, bottom: y, right: width, top: height + y };
18
- });
19
- const transformationMatrices = embedPdfPages.map(() => [1, 0, 0, 1, 0, 0]);
20
- embeddedPages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
21
- return { embeddedPages, embedPdfBoxes };
22
- };
23
- export const drawEmbeddedPage = (arg) => {
24
- const { page, embeddedPage, embedPdfBox } = arg;
25
- page.drawPage(embeddedPage);
26
- const { mediaBox: mb, bleedBox: bb, trimBox: tb } = embedPdfBox;
27
- page.setMediaBox(mb.x, mb.y, mb.width, mb.height);
28
- page.setBleedBox(bb.x, bb.y, bb.width, bb.height);
29
- page.setTrimBox(tb.x, tb.y, tb.width, tb.height);
30
- };
31
- //# sourceMappingURL=pdfUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pdfUtils.js","sourceRoot":"","sources":["../../../src/pdfUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,WAAW,EAAyC,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAW,MAAM,eAAe,CAAC;AAGvD,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,EAAE,GAGtD,EAAE,EAAE;IACH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAChC,IAAI,aAAa,GAAsB,EAAE,CAAC;IAC1C,IAAI,aAAa,GAAkB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACzF,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,aAAa,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAE1C,aAAa,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACxC,QAAQ,EAAE,CAAC,CAAC,WAAW,EAAE;QACzB,QAAQ,EAAE,CAAC,CAAC,WAAW,EAAE;QACzB,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE;KACxB,CAAC,CAAC,CAAC;IAEJ,MAAM,aAAa,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5C,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,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D,CAAC,CAAC"}
@@ -1,15 +0,0 @@
1
- import { PDFPage, PDFDocument, PDFEmbeddedPage } from '@pdfme/pdf-lib';
2
- import { BasePdf } from '@pdfme/common';
3
- import type { EmbedPdfBox } from './types';
4
- export declare const getEmbeddedPagesAndEmbedPdfBoxes: (arg: {
5
- pdfDoc: PDFDocument;
6
- basePdf: BasePdf;
7
- }) => Promise<{
8
- embeddedPages: PDFEmbeddedPage[];
9
- embedPdfBoxes: EmbedPdfBox[];
10
- }>;
11
- export declare const drawEmbeddedPage: (arg: {
12
- page: PDFPage;
13
- embeddedPage: PDFEmbeddedPage;
14
- embedPdfBox: EmbedPdfBox;
15
- }) => void;
package/src/pdfUtils.ts DELETED
@@ -1,48 +0,0 @@
1
- import { PDFPage, PDFDocument, PDFEmbeddedPage, TransformationMatrix } from '@pdfme/pdf-lib';
2
- import { getB64BasePdf, BasePdf } from '@pdfme/common';
3
- import type { EmbedPdfBox } from './types';
4
-
5
- export const getEmbeddedPagesAndEmbedPdfBoxes = async (arg: {
6
- pdfDoc: PDFDocument;
7
- basePdf: BasePdf;
8
- }) => {
9
- const { pdfDoc, basePdf } = arg;
10
- let embeddedPages: PDFEmbeddedPage[] = [];
11
- let embedPdfBoxes: EmbedPdfBox[] = [];
12
- const willLoadPdf = typeof basePdf === 'string' ? await getB64BasePdf(basePdf) : basePdf;
13
- const embedPdf = await PDFDocument.load(willLoadPdf);
14
- const embedPdfPages = embedPdf.getPages();
15
-
16
- embedPdfBoxes = embedPdfPages.map((p) => ({
17
- mediaBox: p.getMediaBox(),
18
- bleedBox: p.getBleedBox(),
19
- trimBox: p.getTrimBox(),
20
- }));
21
-
22
- const boundingBoxes = embedPdfPages.map((p) => {
23
- const { x, y, width, height } = p.getMediaBox();
24
-
25
- return { left: x, bottom: y, right: width, top: height + y };
26
- });
27
-
28
- const transformationMatrices = embedPdfPages.map(
29
- () => [1, 0, 0, 1, 0, 0] as TransformationMatrix
30
- );
31
-
32
- embeddedPages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
33
-
34
- return { embeddedPages, embedPdfBoxes };
35
- };
36
-
37
- export const drawEmbeddedPage = (arg: {
38
- page: PDFPage;
39
- embeddedPage: PDFEmbeddedPage;
40
- embedPdfBox: EmbedPdfBox;
41
- }) => {
42
- const { page, embeddedPage, embedPdfBox } = arg;
43
- page.drawPage(embeddedPage);
44
- const { mediaBox: mb, bleedBox: bb, trimBox: tb } = embedPdfBox;
45
- page.setMediaBox(mb.x, mb.y, mb.width, mb.height);
46
- page.setBleedBox(bb.x, bb.y, bb.width, bb.height);
47
- page.setTrimBox(tb.x, tb.y, tb.width, tb.height);
48
- };