pdf-creator-node 2.4.0 → 2.5.0
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/createPdf.d.ts.map +1 -1
- package/dist/createPdf.js +2 -16
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/pdfChrome.d.ts +12 -0
- package/dist/pdfChrome.d.ts.map +1 -0
- package/dist/pdfChrome.js +117 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/readme.md +22 -0
package/dist/createPdf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPdf.d.ts","sourceRoot":"","sources":["../src/createPdf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createPdf.d.ts","sourceRoot":"","sources":["../src/createPdf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAmB7D;;GAEG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,cAAc,GAAG,QAAQ,CAAC,CA2CpD"}
|
package/dist/createPdf.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -17,12 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
6
|
exports.create = create;
|
|
18
7
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
19
8
|
const html_pdf_1 = __importDefault(require("html-pdf"));
|
|
9
|
+
const pdfChrome_1 = require("./pdfChrome");
|
|
20
10
|
const registerHandlebarsHelpers_1 = require("./registerHandlebarsHelpers");
|
|
21
11
|
const validation_1 = require("./validation");
|
|
22
|
-
function stripHtmlPdfOptions(options) {
|
|
23
|
-
const { handlebarsHelpers: _h } = options, rest = __rest(options, ["handlebarsHelpers"]);
|
|
24
|
-
return rest;
|
|
25
|
-
}
|
|
26
12
|
function renderHtml(document, options) {
|
|
27
13
|
const hb = handlebars_1.default.create();
|
|
28
14
|
(0, registerHandlebarsHelpers_1.registerHandlebarsHelpers)(hb);
|
|
@@ -59,7 +45,7 @@ function create(document, options) {
|
|
|
59
45
|
reject(e);
|
|
60
46
|
return;
|
|
61
47
|
}
|
|
62
|
-
const pdfOptions =
|
|
48
|
+
const pdfOptions = (0, pdfChrome_1.mergePdfCreateOptions)(options);
|
|
63
49
|
const pdfPromise = html_pdf_1.default.create(html, pdfOptions);
|
|
64
50
|
switch (document.type) {
|
|
65
51
|
case "buffer":
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { create } from "./createPdf";
|
|
5
5
|
export { create };
|
|
6
|
-
export
|
|
6
|
+
export { buildPdfChrome } from "./pdfChrome";
|
|
7
|
+
export type { Document, IfCondOptions, PdfChromeOptions, PdfCreateOptions, PdfDocument, PdfDocumentBuffer, PdfDocumentFile, PdfDocumentStream, PdfFooterConfig, PdfHeaderConfig, PdfLayout, } from "./types";
|
|
7
8
|
declare const api: {
|
|
8
9
|
create: typeof create;
|
|
9
10
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EACV,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EACV,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,SAAS,GACV,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,GAAG;;CAAa,CAAC;AACvB,eAAe,GAAG,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* @author Shyam Hajare <hajareshyam@gmail.com>
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.create = void 0;
|
|
6
|
+
exports.buildPdfChrome = exports.create = void 0;
|
|
7
7
|
const registerHandlebarsHelpers_1 = require("./registerHandlebarsHelpers");
|
|
8
8
|
const createPdf_1 = require("./createPdf");
|
|
9
9
|
Object.defineProperty(exports, "create", { enumerable: true, get: function () { return createPdf_1.create; } });
|
|
10
10
|
(0, registerHandlebarsHelpers_1.registerHandlebarsHelpers)();
|
|
11
|
+
var pdfChrome_1 = require("./pdfChrome");
|
|
12
|
+
Object.defineProperty(exports, "buildPdfChrome", { enumerable: true, get: function () { return pdfChrome_1.buildPdfChrome; } });
|
|
11
13
|
const api = { create: createPdf_1.create };
|
|
12
14
|
exports.default = api;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CreateOptions } from "html-pdf";
|
|
2
|
+
import type { PdfChromeOptions, PdfCreateOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Builds partial html-pdf options from layout / header / footer / copyright.
|
|
5
|
+
* Use {@link mergePdfCreateOptions} to merge with explicit `format`, `header`, `footer`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildPdfChrome(chrome?: PdfChromeOptions): Partial<CreateOptions>;
|
|
8
|
+
/**
|
|
9
|
+
* Merges `pdfChrome` with explicit html-pdf fields. Explicit `header` / `footer` / `format` win.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergePdfCreateOptions(options: PdfCreateOptions): CreateOptions;
|
|
12
|
+
//# sourceMappingURL=pdfChrome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfChrome.d.ts","sourceRoot":"","sources":["../src/pdfChrome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA+ClE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAuDhF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAS9E"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.buildPdfChrome = buildPdfChrome;
|
|
15
|
+
exports.mergePdfCreateOptions = mergePdfCreateOptions;
|
|
16
|
+
function escapeHtml(s) {
|
|
17
|
+
return s
|
|
18
|
+
.replace(/&/g, "&")
|
|
19
|
+
.replace(/</g, "<")
|
|
20
|
+
.replace(/>/g, ">")
|
|
21
|
+
.replace(/"/g, """);
|
|
22
|
+
}
|
|
23
|
+
function defaultHeaderHtml(title) {
|
|
24
|
+
return `<div style="text-align:center;font-size:10px;padding:6px;">${escapeHtml(title)}</div>`;
|
|
25
|
+
}
|
|
26
|
+
function buildFooterContents(copyright, showPageNumbers) {
|
|
27
|
+
const hasCopyright = copyright != null && String(copyright).trim() !== "";
|
|
28
|
+
const pagePart = showPageNumbers
|
|
29
|
+
? '<span style="color:#444">{{page}}</span>/<span>{{pages}}</span>'
|
|
30
|
+
: "";
|
|
31
|
+
if (hasCopyright && pagePart) {
|
|
32
|
+
return {
|
|
33
|
+
default: `<div style="text-align:center;font-size:9px;padding:4px;">${escapeHtml(String(copyright))} · ${pagePart}</div>`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (hasCopyright) {
|
|
37
|
+
return {
|
|
38
|
+
default: `<div style="text-align:center;font-size:9px;padding:4px;">${escapeHtml(String(copyright))}</div>`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (pagePart) {
|
|
42
|
+
return {
|
|
43
|
+
default: `<div style="text-align:center;font-size:9px;padding:4px;">${pagePart}</div>`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return { default: "" };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Builds partial html-pdf options from layout / header / footer / copyright.
|
|
50
|
+
* Use {@link mergePdfCreateOptions} to merge with explicit `format`, `header`, `footer`.
|
|
51
|
+
*/
|
|
52
|
+
function buildPdfChrome(chrome) {
|
|
53
|
+
var _a, _b, _c, _d;
|
|
54
|
+
if (!chrome)
|
|
55
|
+
return {};
|
|
56
|
+
const out = {};
|
|
57
|
+
if (chrome.layout) {
|
|
58
|
+
const L = chrome.layout;
|
|
59
|
+
if (L.format)
|
|
60
|
+
out.format = L.format;
|
|
61
|
+
if (L.orientation)
|
|
62
|
+
out.orientation = L.orientation;
|
|
63
|
+
if (L.width)
|
|
64
|
+
out.width = L.width;
|
|
65
|
+
if (L.height)
|
|
66
|
+
out.height = L.height;
|
|
67
|
+
if (L.border !== undefined)
|
|
68
|
+
out.border = L.border;
|
|
69
|
+
}
|
|
70
|
+
if (chrome.header) {
|
|
71
|
+
const h = chrome.header;
|
|
72
|
+
const contents = (_a = h.html) !== null && _a !== void 0 ? _a : (h.title != null && h.title !== "" ? defaultHeaderHtml(h.title) : undefined);
|
|
73
|
+
if (contents) {
|
|
74
|
+
out.header = {
|
|
75
|
+
height: (_b = h.height) !== null && _b !== void 0 ? _b : "45mm",
|
|
76
|
+
contents,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else if (h.height) {
|
|
80
|
+
out.header = { height: h.height };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (chrome.footer) {
|
|
84
|
+
const f = chrome.footer;
|
|
85
|
+
if (f.html) {
|
|
86
|
+
out.footer = {
|
|
87
|
+
height: (_c = f.height) !== null && _c !== void 0 ? _c : "28mm",
|
|
88
|
+
contents: { default: f.html },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const hasCopyright = f.copyright != null && String(f.copyright).trim() !== "";
|
|
93
|
+
const showPages = f.showPageNumbers === true ||
|
|
94
|
+
(f.showPageNumbers !== false && hasCopyright);
|
|
95
|
+
if (hasCopyright || showPages) {
|
|
96
|
+
const contents = buildFooterContents(hasCopyright ? String(f.copyright) : undefined, showPages);
|
|
97
|
+
out.footer = {
|
|
98
|
+
height: (_d = f.height) !== null && _d !== void 0 ? _d : "28mm",
|
|
99
|
+
contents,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
else if (f.height) {
|
|
103
|
+
out.footer = { height: f.height };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Merges `pdfChrome` with explicit html-pdf fields. Explicit `header` / `footer` / `format` win.
|
|
111
|
+
*/
|
|
112
|
+
function mergePdfCreateOptions(options) {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
const { handlebarsHelpers: _h, pdfChrome } = options, userPdfOptions = __rest(options, ["handlebarsHelpers", "pdfChrome"]);
|
|
115
|
+
const fromChrome = buildPdfChrome(pdfChrome);
|
|
116
|
+
return Object.assign(Object.assign(Object.assign({}, fromChrome), userPdfOptions), { header: (_a = userPdfOptions.header) !== null && _a !== void 0 ? _a : fromChrome.header, footer: (_b = userPdfOptions.footer) !== null && _b !== void 0 ? _b : fromChrome.footer });
|
|
117
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -29,11 +29,51 @@ export interface PdfDocumentStream {
|
|
|
29
29
|
export type PdfDocument = PdfDocumentFile | PdfDocumentBuffer | PdfDocumentStream;
|
|
30
30
|
/** @deprecated Use `PdfDocument` — kept for compatibility with earlier typings */
|
|
31
31
|
export type Document = PdfDocument;
|
|
32
|
+
/** Page size / margins — maps to html-pdf paper options */
|
|
33
|
+
export interface PdfLayout {
|
|
34
|
+
format?: "A3" | "A4" | "A5" | "Legal" | "Letter" | "Tabloid";
|
|
35
|
+
orientation?: "portrait" | "landscape";
|
|
36
|
+
width?: string;
|
|
37
|
+
height?: string;
|
|
38
|
+
border?: CreateOptions["border"];
|
|
39
|
+
}
|
|
40
|
+
/** Repeating header — use `html` or a plain `title` (escaped) */
|
|
41
|
+
export interface PdfHeaderConfig {
|
|
42
|
+
height?: string;
|
|
43
|
+
/** Raw HTML shown on each page */
|
|
44
|
+
html?: string;
|
|
45
|
+
/** Centered plain text (HTML-escaped). Ignored if `html` is set */
|
|
46
|
+
title?: string;
|
|
47
|
+
}
|
|
48
|
+
/** Repeating footer — use `html`, or `copyright` / `showPageNumbers` */
|
|
49
|
+
export interface PdfFooterConfig {
|
|
50
|
+
height?: string;
|
|
51
|
+
/** Raw HTML for the default footer slot */
|
|
52
|
+
html?: string;
|
|
53
|
+
/** Plain copyright line (HTML-escaped) */
|
|
54
|
+
copyright?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Include `{{page}}` / `{{pages}}`. If `copyright` is set, defaults to true unless `false`.
|
|
57
|
+
* For page numbers only, set `showPageNumbers: true` and omit `copyright`.
|
|
58
|
+
*/
|
|
59
|
+
showPageNumbers?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* High-level layout + header/footer/copyright. Merged before `html-pdf` runs; any
|
|
63
|
+
* explicit `format`, `header`, `footer` on the same options object overrides these.
|
|
64
|
+
*/
|
|
65
|
+
export interface PdfChromeOptions {
|
|
66
|
+
layout?: PdfLayout;
|
|
67
|
+
header?: PdfHeaderConfig;
|
|
68
|
+
footer?: PdfFooterConfig;
|
|
69
|
+
}
|
|
32
70
|
/**
|
|
33
71
|
* Options for `html-pdf`, plus optional Handlebars helpers for this render only
|
|
34
72
|
* (rendering uses an isolated Handlebars instance).
|
|
35
73
|
*/
|
|
36
74
|
export type PdfCreateOptions = CreateOptions & {
|
|
37
75
|
handlebarsHelpers?: Record<string, HelperDelegate>;
|
|
76
|
+
/** Convenience presets merged into html-pdf options (explicit keys override) */
|
|
77
|
+
pdfChrome?: PdfChromeOptions;
|
|
38
78
|
};
|
|
39
79
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,CAAC;IAC7B,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC;CACpB;AAED,0BAA0B;AAC1B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,+BAA+B;AAC/B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,MAAM,WAAW,GACnB,eAAe,GACf,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB,kFAAkF;AAClF,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC;AAEnC;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,CAAC;IAC7B,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC;CACpB;AAED,0BAA0B;AAC1B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,+BAA+B;AAC/B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,MAAM,WAAW,GACnB,eAAe,GACf,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB,kFAAkF;AAClF,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC;AAEnC,2DAA2D;AAC3D,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC7D,WAAW,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClC;AAED,iEAAiE;AACjE,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACnD,gFAAgF;IAChF,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B,CAAC"}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -63,6 +63,28 @@ await pdf.create(document, options);
|
|
|
63
63
|
- **Buffer:** `type: "buffer"`.
|
|
64
64
|
- **Stream:** `type: "stream"`.
|
|
65
65
|
|
|
66
|
+
### Layout, header, footer, and copyright (`pdfChrome`)
|
|
67
|
+
|
|
68
|
+
Use **`pdfChrome`** on the second argument for common paper layout and repeating header/footer without hand-writing `html-pdf` structures. Plain `title` / `copyright` strings are HTML-escaped.
|
|
69
|
+
|
|
70
|
+
- **`layout`:** `format`, `orientation`, `width`, `height`, `border` (same meaning as [html-pdf](https://www.npmjs.com/package/html-pdf) / Phantom paper size).
|
|
71
|
+
- **`header`:** `html` (raw HTML per page) **or** `title` (centered text). Default height `45mm` when content is set.
|
|
72
|
+
- **`footer`:** `html` **or** combine **`copyright`** with optional **`showPageNumbers`** (`{{page}}` / `{{pages}}`). With `copyright` only, page numbers default **on** unless you set `showPageNumbers: false`. For **page numbers only**, set `showPageNumbers: true` and omit `copyright`. Default footer height `28mm` when content is set.
|
|
73
|
+
|
|
74
|
+
Anything you set directly on the options object (`format`, `header`, `footer`, …) **overrides** the matching field from `pdfChrome`.
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
pdf.create(document, {
|
|
78
|
+
pdfChrome: {
|
|
79
|
+
layout: { format: "A4", orientation: "portrait", border: "12mm" },
|
|
80
|
+
header: { title: "Quarterly report" },
|
|
81
|
+
footer: { copyright: "© 2026 My Company", showPageNumbers: true },
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Advanced: `buildPdfChrome(pdfChrome)` returns partial html-pdf options if you want to compose manually (also exported from the package).
|
|
87
|
+
|
|
66
88
|
### Optional Handlebars helpers
|
|
67
89
|
|
|
68
90
|
Pass `handlebarsHelpers` on the **second** argument (alongside `html-pdf` options). Helpers apply only to that render (isolated Handlebars instance). Built-in `ifCond` is always registered.
|