@things-factory/pdf 10.1.226 → 10.1.227
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PdfTemplateParts } from './pdf-document';
|
|
2
2
|
/** Whether the page may load a request — only what it carries. */
|
|
3
3
|
export declare const loadsOnly: (url: string) => boolean;
|
|
4
4
|
export declare class PdfService {
|
|
5
|
-
|
|
5
|
+
/** A stored template, or the parts of one a module lays out in code (organization's employee profiles). */
|
|
6
|
+
generatePdf(template: PdfTemplateParts, data: any): Promise<Buffer>;
|
|
6
7
|
}
|
|
@@ -22,6 +22,7 @@ const pool = (0, shell_1.getOrCreateHeadlessPool)('pdf', {
|
|
|
22
22
|
const loadsOnly = (url) => url.startsWith('data:') || url === 'about:blank';
|
|
23
23
|
exports.loadsOnly = loadsOnly;
|
|
24
24
|
class PdfService {
|
|
25
|
+
/** A stored template, or the parts of one a module lays out in code (organization's employee profiles). */
|
|
25
26
|
async generatePdf(template, data) {
|
|
26
27
|
const document = (0, pdf_document_1.composePdfDocument)(template, data);
|
|
27
28
|
const browser = await pool.acquire();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-service.js","sourceRoot":"","sources":["../../server/controller/pdf-service.ts"],"names":[],"mappings":";;;AAAA,iDAA4F;
|
|
1
|
+
{"version":3,"file":"pdf-service.js","sourceRoot":"","sources":["../../server/controller/pdf-service.ts"],"names":[],"mappings":";;;AAAA,iDAA4F;AAE5F,iDAAqE;AAErE;;;;;;GAMG;AACH,MAAM,IAAI,GAAG,IAAA,+BAAuB,EAAC,KAAK,EAAE;IAC1C,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,GAAG,EAAE,EAAE,CAAC;IAC3D,IAAI,EAAE,CAAC,GAAG,mCAA2B,CAAC,KAAK,EAAE,GAAG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gBAC3B,cAAc,EAAE,QAAQ,CAAC,cAAc,IAAI,eAAe;gBAC1D,cAAc,EAAE,QAAQ,CAAC,cAAc,IAAI,eAAe;gBAC1D,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;aACrH,CAAC,CACH,CAAA;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;YAClC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;CACF;AA1BD,gCA0BC","sourcesContent":["import { getOrCreateHeadlessPool, HEADLESS_POOL_ARGUMENT_SETS } from '@things-factory/shell'\n\nimport { composePdfDocument, PdfTemplateParts } from './pdf-document'\n\n/*\n * A template filled and printed to PDF in a headless browser from the shell's pool, as board-service prints a\n * board. No browser stays idle (min 0); the first print after a while waits a second or two.\n *\n * The page may load nothing but what it carries (data: URLs): a template that pointed at an address would make\n * the server fetch it.\n */\nconst pool = getOrCreateHeadlessPool('pdf', {\n min: 0,\n max: parseInt(process.env.HEADLESS_POOL_PDF_MAX ?? '4', 10),\n args: [...HEADLESS_POOL_ARGUMENT_SETS.basic, ...HEADLESS_POOL_ARGUMENT_SETS.keychain_safe],\n acquireTimeoutMillis: 15000,\n testOnBorrow: true,\n enableCleanup: true\n})\n\n/** Whether the page may load a request — only what it carries. */\nexport const loadsOnly = (url: string) => url.startsWith('data:') || url === 'about:blank'\n\nexport class PdfService {\n /** A stored template, or the parts of one a module lays out in code (organization's employee profiles). */\n async generatePdf(template: PdfTemplateParts, data: any): Promise<Buffer> {\n const document = composePdfDocument(template, data)\n const browser: any = await pool.acquire()\n const page = await browser.newPage()\n try {\n await page.setRequestInterception(true)\n page.on('request', (request: any) => (loadsOnly(request.url()) ? request.continue() : request.abort()))\n await page.setContent(document.html, { waitUntil: 'load' })\n const framed = !!(document.headerTemplate || document.footerTemplate)\n return Buffer.from(\n await page.pdf({\n format: document.format,\n printBackground: true,\n displayHeaderFooter: framed,\n headerTemplate: document.headerTemplate ?? '<span></span>',\n footerTemplate: document.footerTemplate ?? '<span></span>',\n ...(framed ? { margin: { top: '20mm', bottom: '20mm', left: '12mm', right: '12mm' } } : { preferCSSPageSize: true })\n })\n )\n } finally {\n await page.close().catch(() => {})\n await pool.release(browser)\n }\n }\n}\n"]}
|