@spinajs/templates-pdf 2.0.433 → 2.0.436

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.
@@ -0,0 +1,82 @@
1
+ import { Browser, Page, LaunchOptions } from 'puppeteer';
2
+ import { TemplateRenderer, Templates } from '@spinajs/templates';
3
+ import { Log } from '@spinajs/log';
4
+ import * as http from 'http';
5
+ export interface IPdfRendererOptions {
6
+ static: {
7
+ portRange: number[];
8
+ };
9
+ args: LaunchOptions;
10
+ /**
11
+ * Optional path to Chrome/Chromium executable.
12
+ * Useful when running in environments where Puppeteer cannot download Chromium.
13
+ * If provided, overrides args.executablePath.
14
+ */
15
+ executablePath?: string;
16
+ renderDurationWarning: number;
17
+ navigationTimeout?: number;
18
+ renderTimeout?: number;
19
+ /**
20
+ * Debug options
21
+ */
22
+ debug?: {
23
+ /**
24
+ * If true, browser will remain open after rendering for inspection
25
+ * Use it with headless: false in args to see the browser window ( puppetter.launch args )
26
+ */
27
+ close?: boolean;
28
+ };
29
+ }
30
+ export interface RenderContext {
31
+ server: http.Server;
32
+ browser: Browser;
33
+ page: Page;
34
+ compiledTemplate: string;
35
+ renderTimeout?: NodeJS.Timeout;
36
+ eventCleanup: () => void;
37
+ }
38
+ /**
39
+ * Base class for PDF-based template renderers
40
+ * Provides common functionality for rendering templates using Puppeteer
41
+ */
42
+ export declare abstract class BasePdfTemplate extends TemplateRenderer {
43
+ protected Options: IPdfRendererOptions;
44
+ protected Log: Log;
45
+ protected TemplatingService: Templates;
46
+ protected static USED_PORTS: number[];
47
+ renderToFile(template: string, model: any, filePath: string, language?: string): Promise<void>;
48
+ /**
49
+ * Setup the rendering context (server, browser, page, compiled template)
50
+ */
51
+ protected setupRenderContext(template: string, model: any, language?: string): Promise<RenderContext>;
52
+ /**
53
+ * Perform the actual rendering operation - to be implemented by subclasses
54
+ */
55
+ protected abstract performRender(context: RenderContext, filePath: string): Promise<void>;
56
+ /**
57
+ * Cleanup resources after rendering
58
+ */
59
+ protected cleanup(context: Partial<RenderContext>): Promise<void>;
60
+ /**
61
+ * Run local HTTP server for serving static assets
62
+ */
63
+ protected runLocalServer(basePath: string): Promise<http.Server>;
64
+ /**
65
+ * Enhanced browser cleanup with error handling
66
+ */
67
+ protected safeBrowserCleanup(browser: Browser): Promise<void>;
68
+ /**
69
+ * Force close browser with process termination
70
+ */
71
+ protected forceCloseBrowser(browser: Browser): Promise<void>;
72
+ /**
73
+ * Enhanced server cleanup with timeout
74
+ */
75
+ protected safeServerCleanup(server: http.Server): Promise<void>;
76
+ /**
77
+ * Add page event listeners with cleanup function
78
+ */
79
+ protected addPageEventListeners(page: Page): () => void;
80
+ protected compile(_path: string): Promise<void>;
81
+ }
82
+ //# sourceMappingURL=BasePdfTemplate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BasePdfTemplate.d.ts","sourceRoot":"","sources":["../../src/BasePdfTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAwB,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIjE,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,IAAI,EAAE,aAAa,CAAC;IAEpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,KAAK,CAAC,EAAE;QACN;;;WAGG;QACH,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;CACH;AAED,MAAM,WAAW,aAAa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AC,IAAI,CAAC;IAYlE;;OAEG;cACa,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BrE;;OAEG;IACH,SAAS,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,IAAI;cA0BvC,OAAO,CAAC,KAAK,EAAE,MAAM;CACtC"}
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BasePdfTemplate = void 0;
16
+ const puppeteer_1 = __importDefault(require("puppeteer"));
17
+ const templates_1 = require("@spinajs/templates");
18
+ const configuration_1 = require("@spinajs/configuration");
19
+ const di_1 = require("@spinajs/di");
20
+ const path_1 = require("path");
21
+ const log_1 = require("@spinajs/log");
22
+ const express_1 = __importDefault(require("express"));
23
+ const cors_1 = __importDefault(require("cors"));
24
+ const lodash_1 = __importDefault(require("lodash"));
25
+ /**
26
+ * Base class for PDF-based template renderers
27
+ * Provides common functionality for rendering templates using Puppeteer
28
+ */
29
+ class BasePdfTemplate extends templates_1.TemplateRenderer {
30
+ async renderToFile(template, model, filePath, language) {
31
+ let context = {};
32
+ try {
33
+ this.Log.timeStart(`template-rendering-${filePath}`);
34
+ this.Log.trace(`Rendering template ${template} to file ${filePath}`);
35
+ context = await this.setupRenderContext(template, model, language);
36
+ await this.performRender(context, filePath);
37
+ if (context.renderTimeout) {
38
+ clearTimeout(context.renderTimeout);
39
+ }
40
+ if (context.eventCleanup) {
41
+ context.eventCleanup();
42
+ }
43
+ }
44
+ catch (err) {
45
+ this.Log.error(err, `Error rendering template ${template} to file ${filePath}`);
46
+ throw err;
47
+ }
48
+ finally {
49
+ const duration = this.Log.timeEnd(`template-rendering-${filePath}`);
50
+ if (duration > this.Options.renderDurationWarning) {
51
+ this.Log.warn(`Rendering took too long: ${duration}ms`);
52
+ }
53
+ await this.cleanup(context);
54
+ }
55
+ }
56
+ /**
57
+ * Setup the rendering context (server, browser, page, compiled template)
58
+ */
59
+ async setupRenderContext(template, model, language) {
60
+ const templateBasePath = (0, path_1.dirname)(template);
61
+ // Fire up local http server for serving images etc
62
+ const server = await this.runLocalServer(templateBasePath);
63
+ const httpPort = server.address().port;
64
+ const compiledTemplate = await this.TemplatingService.render((0, path_1.join)(templateBasePath, (0, path_1.basename)(template, this.Extension)) + '.pug', {
65
+ __http_template_port__: httpPort,
66
+ __http_template_address__: `http://localhost:${httpPort}`,
67
+ ...model,
68
+ }, language);
69
+ const launchOptions = {
70
+ ...this.Options.args,
71
+ ...(this.Options.executablePath && {
72
+ executablePath: this.Options.executablePath,
73
+ }),
74
+ };
75
+ const browser = await puppeteer_1.default.launch(launchOptions);
76
+ const page = await browser.newPage();
77
+ // Skip timeouts in debug mode
78
+ if (!this.Options.debug?.close) {
79
+ page.setDefaultNavigationTimeout(this.Options.navigationTimeout || 30000);
80
+ page.setDefaultTimeout(this.Options.renderTimeout || 30000);
81
+ }
82
+ // Set up render timeout (skip in debug mode)
83
+ let renderTimeout;
84
+ if (!this.Options.debug?.close) {
85
+ const timeoutMs = this.Options.renderTimeout || 30000;
86
+ renderTimeout = setTimeout(async () => {
87
+ this.Log.warn(`Render timeout (${timeoutMs}ms) - forcing cleanup`);
88
+ try {
89
+ if (page)
90
+ await page.close().catch(() => { });
91
+ if (browser)
92
+ await this.forceCloseBrowser(browser);
93
+ }
94
+ catch (err) {
95
+ this.Log.error('Error during timeout cleanup:', err);
96
+ }
97
+ }, timeoutMs);
98
+ }
99
+ const eventCleanup = this.addPageEventListeners(page);
100
+ await page.setBypassCSP(true);
101
+ await page.setContent(compiledTemplate);
102
+ return {
103
+ server,
104
+ browser,
105
+ page,
106
+ compiledTemplate,
107
+ renderTimeout,
108
+ eventCleanup,
109
+ };
110
+ }
111
+ /**
112
+ * Cleanup resources after rendering
113
+ */
114
+ async cleanup(context) {
115
+ // Skip browser cleanup if debug.close is false
116
+ if (context.browser && this.Options.debug?.close !== false) {
117
+ await this.safeBrowserCleanup(context.browser);
118
+ }
119
+ else if (context.browser) {
120
+ this.Log.info('Browser kept open for debugging (debug.close=false)');
121
+ }
122
+ if (context.server) {
123
+ await this.safeServerCleanup(context.server);
124
+ }
125
+ }
126
+ /**
127
+ * Run local HTTP server for serving static assets
128
+ */
129
+ async runLocalServer(basePath) {
130
+ const self = this;
131
+ const app = (0, express_1.default)();
132
+ app.use((0, cors_1.default)());
133
+ app.use(express_1.default.static(basePath));
134
+ return new Promise((resolve, reject) => {
135
+ const server = app
136
+ .listen(this.Options.static.portRange.length === 0
137
+ ? 0
138
+ : lodash_1.default.random(this.Options.static.portRange[0], this.Options.static.portRange[1]))
139
+ .on('listening', function () {
140
+ self.Log.trace(`Static server started on port ${this.address().port}`);
141
+ self.Log.trace(`Static file dir at ${basePath}`);
142
+ resolve(this);
143
+ })
144
+ .on('error', (err) => {
145
+ self.Log.error(err, `Static server cannot start`);
146
+ if (server) {
147
+ server.close(() => {
148
+ reject(err);
149
+ });
150
+ }
151
+ else {
152
+ reject(err);
153
+ }
154
+ });
155
+ setTimeout(() => {
156
+ if (!server.listening) {
157
+ server.close();
158
+ reject(new Error('Server startup timeout'));
159
+ }
160
+ }, 10000);
161
+ });
162
+ }
163
+ /**
164
+ * Enhanced browser cleanup with error handling
165
+ */
166
+ async safeBrowserCleanup(browser) {
167
+ try {
168
+ const pages = await browser.pages();
169
+ await Promise.allSettled(pages.map((page) => page.close()));
170
+ await browser.close();
171
+ }
172
+ catch (err) {
173
+ this.Log.warn(`Error during normal browser cleanup: ${err.message}`);
174
+ try {
175
+ await this.forceCloseBrowser(browser);
176
+ }
177
+ catch (killErr) {
178
+ this.Log.error(`Failed to force kill browser: ${killErr.message}`);
179
+ }
180
+ }
181
+ }
182
+ /**
183
+ * Force close browser with process termination
184
+ */
185
+ async forceCloseBrowser(browser) {
186
+ try {
187
+ const process = browser.process();
188
+ if (process) {
189
+ process.kill('SIGKILL');
190
+ this.Log.warn('Browser process force killed');
191
+ }
192
+ }
193
+ catch (err) {
194
+ this.Log.error(`Error force killing browser process: ${err.message}`);
195
+ }
196
+ }
197
+ /**
198
+ * Enhanced server cleanup with timeout
199
+ */
200
+ async safeServerCleanup(server) {
201
+ try {
202
+ await new Promise((resolve, reject) => {
203
+ const timeout = setTimeout(() => {
204
+ reject(new Error('Server close timeout'));
205
+ }, 5000);
206
+ server.close((err) => {
207
+ clearTimeout(timeout);
208
+ if (err)
209
+ reject(err);
210
+ else
211
+ resolve();
212
+ });
213
+ });
214
+ }
215
+ catch (err) {
216
+ this.Log.warn(`Error closing server: ${err.message}`);
217
+ try {
218
+ if ('closeAllConnections' in server) {
219
+ server.closeAllConnections();
220
+ }
221
+ }
222
+ catch (forceErr) {
223
+ this.Log.error(`Error force closing server connections: ${forceErr.message}`);
224
+ }
225
+ }
226
+ }
227
+ /**
228
+ * Add page event listeners with cleanup function
229
+ */
230
+ addPageEventListeners(page) {
231
+ const listeners = {
232
+ console: (message) => this.Log.trace(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`),
233
+ pageerror: ({ message }) => this.Log.error(message),
234
+ response: (response) => this.Log.trace(`${response.status()} ${response.url()}`),
235
+ requestfailed: (request) => this.Log.error(`${request.failure().errorText} ${request.url()}`),
236
+ };
237
+ page.on('console', listeners.console);
238
+ page.on('pageerror', listeners.pageerror);
239
+ page.on('response', listeners.response);
240
+ page.on('requestfailed', listeners.requestfailed);
241
+ return () => {
242
+ try {
243
+ page.removeAllListeners('console');
244
+ page.removeAllListeners('pageerror');
245
+ page.removeAllListeners('response');
246
+ page.removeAllListeners('requestfailed');
247
+ }
248
+ catch (err) {
249
+ this.Log.warn(`Error removing page listeners: ${err.message}`);
250
+ }
251
+ };
252
+ }
253
+ // No compilation at start
254
+ async compile(_path) { }
255
+ }
256
+ exports.BasePdfTemplate = BasePdfTemplate;
257
+ BasePdfTemplate.USED_PORTS = [];
258
+ __decorate([
259
+ (0, configuration_1.Config)('templates.pdf'),
260
+ __metadata("design:type", Object)
261
+ ], BasePdfTemplate.prototype, "Options", void 0);
262
+ __decorate([
263
+ (0, log_1.Logger)('pdf-templates'),
264
+ __metadata("design:type", log_1.Log)
265
+ ], BasePdfTemplate.prototype, "Log", void 0);
266
+ __decorate([
267
+ (0, di_1.LazyInject)(),
268
+ __metadata("design:type", templates_1.Templates)
269
+ ], BasePdfTemplate.prototype, "TemplatingService", void 0);
270
+ //# sourceMappingURL=BasePdfTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BasePdfTemplate.js","sourceRoot":"","sources":["../../src/BasePdfTemplate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAA+E;AAC/E,kDAAiE;AACjE,0DAAgD;AAChD,oCAAyC;AACzC,+BAA+C;AAC/C,sCAA2C;AAC3C,sDAA8B;AAE9B,gDAAwB;AACxB,oDAAuB;AAwCvB;;;GAGG;AACH,MAAsB,eAAgB,SAAQ,4BAAgB;IAYrD,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,KAAU,EAAE,QAAgB,EAAE,QAAiB;QACzF,IAAI,OAAO,GAA2B,EAAE,CAAC;QAEzC,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,SAAS,CA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,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YACjE,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAED,0BAA0B;IAChB,KAAK,CAAC,OAAO,CAAC,KAAa,IAAG,CAAC;;AA3Q3C,0CA4QC;AAlQkB,0BAAU,GAAa,EAAE,CAAC;AARjC;IADT,IAAA,sBAAM,EAAC,eAAe,CAAC;;gDACe;AAG7B;IADT,IAAA,YAAM,EAAC,eAAe,CAAC;8BACT,SAAG;4CAAC;AAGT;IADT,IAAA,eAAU,GAAE;8BACgB,qBAAS;0DAAC"}
@@ -0,0 +1,20 @@
1
+ import { PDFOptions } from 'puppeteer';
2
+ import { IInstanceCheck } from '@spinajs/di';
3
+ import { BasePdfTemplate, RenderContext } from './BasePdfTemplate.js';
4
+ import '@spinajs/templates-pug';
5
+ /**
6
+ * PDF renderer that generates PDF files from templates
7
+ */
8
+ export declare class PdfRenderer extends BasePdfTemplate implements IInstanceCheck {
9
+ protected pdfOptions: PDFOptions;
10
+ get Type(): string;
11
+ get Extension(): string;
12
+ constructor(pdfOptions: PDFOptions);
13
+ __checkInstance__(creationOptions: any): boolean;
14
+ /**
15
+ * Perform PDF rendering
16
+ */
17
+ protected performRender(context: RenderContext, filePath: string): Promise<void>;
18
+ render(_templateName: string, _model: unknown, _language?: string): Promise<string>;
19
+ }
20
+ //# sourceMappingURL=PdfRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PdfRenderer.d.ts","sourceRoot":"","sources":["../../src/PdfRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAgC,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,wBAAwB,CAAC;AAGhC;;GAEG;AACH,qBAEa,WAAY,SAAQ,eAAgB,YAAW,cAAc;IAS5D,SAAS,CAAC,UAAU,EAAE,UAAU;IAR5C,IAAW,IAAI,WAEd;IAED,IAAW,SAAS,WAEnB;gBAEqB,UAAU,EAAE,UAAU;IAI5C,iBAAiB,CAAC,eAAe,EAAE,GAAG,GAAG,OAAO;IAIhD;;OAEG;cACa,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzE,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGjG"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PdfRenderer = void 0;
13
+ const exceptions_1 = require("@spinajs/exceptions");
14
+ const di_1 = require("@spinajs/di");
15
+ const BasePdfTemplate_js_1 = require("./BasePdfTemplate.js");
16
+ require("@spinajs/templates-pug");
17
+ const templates_1 = require("@spinajs/templates");
18
+ /**
19
+ * PDF renderer that generates PDF files from templates
20
+ */
21
+ let PdfRenderer = class PdfRenderer extends BasePdfTemplate_js_1.BasePdfTemplate {
22
+ get Type() {
23
+ return 'pdf';
24
+ }
25
+ get Extension() {
26
+ return '.pdf';
27
+ }
28
+ constructor(pdfOptions) {
29
+ super();
30
+ this.pdfOptions = pdfOptions;
31
+ }
32
+ __checkInstance__(creationOptions) {
33
+ return JSON.stringify(this.pdfOptions) === JSON.stringify(creationOptions);
34
+ }
35
+ /**
36
+ * Perform PDF rendering
37
+ */
38
+ async performRender(context, filePath) {
39
+ await context.page.pdf({
40
+ path: filePath,
41
+ ...this.pdfOptions,
42
+ });
43
+ }
44
+ async render(_templateName, _model, _language) {
45
+ throw new exceptions_1.NotSupported('cannot render pdf template to string');
46
+ }
47
+ };
48
+ exports.PdfRenderer = PdfRenderer;
49
+ exports.PdfRenderer = PdfRenderer = __decorate([
50
+ (0, di_1.Injectable)(templates_1.TemplateRenderer),
51
+ (0, di_1.PerInstanceCheck)(),
52
+ __metadata("design:paramtypes", [Object])
53
+ ], PdfRenderer);
54
+ //# sourceMappingURL=PdfRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PdfRenderer.js","sourceRoot":"","sources":["../../src/PdfRenderer.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAAmD;AACnD,oCAA2E;AAC3E,6DAAsE;AAEtE,kCAAgC;AAChC,kDAAsD;AAEtD;;GAEG;AAGI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,oCAAe;IAC9C,IAAW,IAAI;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,YAAsB,UAAsB;QAC1C,KAAK,EAAE,CAAC;QADY,eAAU,GAAV,UAAU,CAAY;IAE5C,CAAC;IAED,iBAAiB,CAAC,eAAoB;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAC7E,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,aAAa,CAAC,OAAsB,EAAE,QAAgB;QACpE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;YACrB,IAAI,EAAE,QAAQ;YACd,GAAG,IAAI,CAAC,UAAU;SACnB,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,aAAqB,EAAE,MAAe,EAAE,SAAkB;QAC5E,MAAM,IAAI,yBAAY,CAAC,sCAAsC,CAAC,CAAC;IACjE,CAAC;CACF,CAAA;AA9BY,kCAAW;sBAAX,WAAW;IAFvB,IAAA,eAAU,EAAC,4BAAgB,CAAC;IAC5B,IAAA,qBAAgB,GAAE;;GACN,WAAW,CA8BvB"}
@@ -0,0 +1,31 @@
1
+ import { PDFOptions, ScreenshotOptions } from 'puppeteer';
2
+ import { IInstanceCheck } from '@spinajs/di';
3
+ import { BasePdfTemplate, RenderContext } from './BasePdfTemplate.js';
4
+ import '@spinajs/templates-pug';
5
+ export interface PdfToImageOptions {
6
+ /**
7
+ * PDF generation options (used as intermediate step)
8
+ */
9
+ pdfOptions?: PDFOptions;
10
+ /**
11
+ * Screenshot/image generation options
12
+ */
13
+ screenshotOptions: ScreenshotOptions;
14
+ }
15
+ /**
16
+ * PDF-to-Image renderer that generates images from PDF templates
17
+ * First renders to PDF, then captures as image
18
+ */
19
+ export declare class PdfToImageRenderer extends BasePdfTemplate implements IInstanceCheck {
20
+ protected imageOptions: PdfToImageOptions;
21
+ get Type(): string;
22
+ get Extension(): string;
23
+ constructor(imageOptions: PdfToImageOptions);
24
+ __checkInstance__(creationOptions: any): boolean;
25
+ /**
26
+ * Perform image rendering from PDF
27
+ */
28
+ protected performRender(context: RenderContext, filePath: string): Promise<void>;
29
+ render(_templateName: string, _model: unknown, _language?: string): Promise<string>;
30
+ }
31
+ //# sourceMappingURL=PdfToImageRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PdfToImageRenderer.d.ts","sourceRoot":"","sources":["../../src/PdfToImageRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAgC,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGtE,OAAO,wBAAwB,CAAC;AAGhC,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED;;;GAGG;AACH,qBAEa,kBAAmB,SAAQ,eAAgB,YAAW,cAAc;IAUnE,SAAS,CAAC,YAAY,EAAE,iBAAiB;IATrD,IAAW,IAAI,WAEd;IAED,IAAW,SAAS,WAGnB;gBAEqB,YAAY,EAAE,iBAAiB;IAIrD,iBAAiB,CAAC,eAAe,EAAE,GAAG,GAAG,OAAO;IAIhD;;OAEG;cACa,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBzE,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGjG"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PdfToImageRenderer = void 0;
13
+ const exceptions_1 = require("@spinajs/exceptions");
14
+ const di_1 = require("@spinajs/di");
15
+ const BasePdfTemplate_js_1 = require("./BasePdfTemplate.js");
16
+ const path_1 = require("path");
17
+ require("@spinajs/templates-pug");
18
+ const templates_1 = require("@spinajs/templates");
19
+ /**
20
+ * PDF-to-Image renderer that generates images from PDF templates
21
+ * First renders to PDF, then captures as image
22
+ */
23
+ let PdfToImageRenderer = class PdfToImageRenderer extends BasePdfTemplate_js_1.BasePdfTemplate {
24
+ get Type() {
25
+ return 'pdf-image';
26
+ }
27
+ get Extension() {
28
+ const type = this.imageOptions.screenshotOptions.type || 'png';
29
+ return `.${type}`;
30
+ }
31
+ constructor(imageOptions) {
32
+ super();
33
+ this.imageOptions = imageOptions;
34
+ }
35
+ __checkInstance__(creationOptions) {
36
+ return JSON.stringify(this.imageOptions) === JSON.stringify(creationOptions);
37
+ }
38
+ /**
39
+ * Perform image rendering from PDF
40
+ */
41
+ async performRender(context, filePath) {
42
+ // Determine image type from file extension or options
43
+ const fileExt = (0, path_1.extname)(filePath).toLowerCase().slice(1);
44
+ const imageType = (fileExt === 'jpg' || fileExt === 'jpeg' || fileExt === 'png' || fileExt === 'webp')
45
+ ? fileExt
46
+ : this.imageOptions.screenshotOptions.type || 'png';
47
+ // Take screenshot
48
+ await context.page.screenshot({
49
+ path: filePath,
50
+ type: imageType,
51
+ ...this.imageOptions.screenshotOptions,
52
+ });
53
+ this.Log.trace(`Generated image from PDF template: ${filePath}`);
54
+ }
55
+ async render(_templateName, _model, _language) {
56
+ throw new exceptions_1.NotSupported('cannot render pdf-image template to string');
57
+ }
58
+ };
59
+ exports.PdfToImageRenderer = PdfToImageRenderer;
60
+ exports.PdfToImageRenderer = PdfToImageRenderer = __decorate([
61
+ (0, di_1.Injectable)(templates_1.TemplateRenderer),
62
+ (0, di_1.PerInstanceCheck)(),
63
+ __metadata("design:paramtypes", [Object])
64
+ ], PdfToImageRenderer);
65
+ //# sourceMappingURL=PdfToImageRenderer.js.map
@@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SAAoC;YAC1C,GAAG,IAAI,CAAC,YAAY,CAAC,iBAAiB;SACvC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,sCAAsC,QAAQ,EAAE,CAAC,CAAC;IACnE,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,aAAqB,EAAE,MAAe,EAAE,SAAkB;QAC5E,MAAM,IAAI,yBAAY,CAAC,4CAA4C,CAAC,CAAC;IACvE,CAAC;CACF,CAAA;AAzCY,gDAAkB;6BAAlB,kBAAkB;IAF9B,IAAA,eAAU,EAAC,4BAAgB,CAAC;IAC5B,IAAA,qBAAgB,GAAE;;GACN,kBAAkB,CAyC9B"}
@@ -1,67 +1,16 @@
1
- import { PDFOptions, LaunchOptions } from 'puppeteer';
2
- import { TemplateRenderer, Templates } from '@spinajs/templates';
1
+ import { Page, PDFOptions } from 'puppeteer';
2
+ import { PuppeteerRenderer, IPuppeteerRendererOptions } from '@spinajs/templates-puppeteer';
3
3
  import { IInstanceCheck } from '@spinajs/di';
4
- import { Log } from '@spinajs/log';
5
- import * as http from 'http';
6
- import '@spinajs/templates-pug';
7
- interface IPdfRendererOptions {
8
- static: {
9
- portRange: number[];
10
- };
11
- args: LaunchOptions;
12
- /**
13
- * Optional path to Chrome/Chromium executable.
14
- * Useful when running in environments where Puppeteer cannot download Chromium.
15
- * If provided, overrides args.executablePath.
16
- */
17
- executablePath?: string;
18
- renderDurationWarning: number;
19
- navigationTimeout?: number;
20
- renderTimeout?: number;
21
- /**
22
- * Debug options
23
- */
24
- debug?: {
25
- /**
26
- * If true, browser will remain open after rendering for inspection
27
- * Use it with headless: false in args to see the browser window ( puppetter.launch args )
28
- */
29
- close?: boolean;
30
- };
31
- }
32
- export declare class PdfRenderer extends TemplateRenderer implements IInstanceCheck {
4
+ export declare class PdfRenderer extends PuppeteerRenderer implements IInstanceCheck {
33
5
  protected pdfOptions: PDFOptions;
34
6
  /**
35
7
  * General options from configuration
36
8
  */
37
- protected Options: IPdfRendererOptions;
38
- protected Log: Log;
39
- protected TemplatingService: Templates;
40
- protected static USED_PORTS: number[];
9
+ protected Options: IPuppeteerRendererOptions;
41
10
  get Type(): string;
42
11
  get Extension(): string;
43
12
  constructor(pdfOptions: PDFOptions);
44
13
  __checkInstance__(creationOptions: any): boolean;
45
- renderToFile(template: string, model: any, filePath: string, language?: string): Promise<void>;
46
- render(_templateName: string, _model: unknown, _language?: string): Promise<string>;
47
- protected compile(_path: string): Promise<void>;
48
- protected runLocalServer(basePath: string): Promise<http.Server>;
49
- /**
50
- * Enhanced browser cleanup with error handling
51
- */
52
- private safeBrowserCleanup;
53
- /**
54
- * Force close browser with process termination
55
- */
56
- private forceCloseBrowser;
57
- /**
58
- * Enhanced server cleanup with timeout
59
- */
60
- private safeServerCleanup;
61
- /**
62
- * Add page event listeners with cleanup function
63
- */
64
- private addPageEventListeners;
14
+ protected performRender(page: Page, filePath: string): Promise<void>;
65
15
  }
66
- export {};
67
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,UAAU,EAAwB,aAAa,EAAE,MAAM,WAAW,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAA4C,MAAM,aAAa,CAAC;AAEvF,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,OAAO,wBAAwB,CAAC;AAIhC,UAAU,mBAAmB;IAC3B,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,IAAI,EAAE,aAAa,CAAC;IAEpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,C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