Skip to content

Commit de43a54

Browse files
committed
chore: release v2.5.0
1 parent cfccfe4 commit de43a54

14 files changed

Lines changed: 360 additions & 714 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules/
2-
.package-lock.json
32
dist/
43
example/output.pdf
54

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## [2.5.0] — 2026-04-03
4+
5+
### Added
6+
7+
- **`pdfChrome`** on `PdfCreateOptions`: structured **layout** (format, orientation, size, border), **header** (`html` or escaped `title`), **footer** (`html` or `copyright` + optional page numbers via `showPageNumbers`). Merged into html-pdf options; explicit `format` / `header` / `footer` on the same object override.
8+
- Exported **`buildPdfChrome()`** for building partial html-pdf options from `PdfChromeOptions`.
9+
- Types: `PdfChromeOptions`, `PdfLayout`, `PdfHeaderConfig`, `PdfFooterConfig`.
10+
11+
### Changed
12+
13+
- **Repository:** removed root `yarn.lock` so installs match **npm** only (aligned with `npm ci` in CI). Keep `package-lock.json` as the lockfile.
14+
- **`.gitignore`:** dropped the `.package-lock.json` ignore rule (misleading; `package-lock.json` remains tracked).
15+
16+
### Documentation
17+
18+
- **Example (`example/`):** sample uses **`pdfChrome`** (layout, header title, footer copyright + page numbers).
19+
- **GitHub Pages (`docs/`):** “Layout & header/footer” section, quick start uses `pdfChrome`, install command `npm i pdf-creator-node`, hero link to full readme.
20+
321
## [2.4.0] — 2026-04-03
422

523
### Added

docs/assets/css/style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ html[data-theme="light"] .theme-toggle__icon--moon {
283283
font-weight: 600;
284284
}
285285

286+
.hero__hint {
287+
margin: 1rem 0 0;
288+
font-size: 0.95rem;
289+
line-height: 1.55;
290+
color: var(--muted);
291+
max-width: 40rem;
292+
}
293+
294+
.hero__hint code {
295+
font-size: 0.88em;
296+
}
297+
286298
.badges {
287299
display: flex;
288300
flex-wrap: wrap;

docs/index.html

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<nav class="site-nav" aria-label="On this page">
3434
<a href="#quick-start">Quick start</a>
3535
<a href="#guide">Guide</a>
36+
<a href="#pdf-chrome">Layout &amp; header/footer</a>
3637
<a href="#ifcond">ifCond</a>
3738
</nav>
3839
<div class="site-header__actions">
@@ -99,9 +100,14 @@ <h1>pdf-creator-node</h1>
99100
>Source on GitHub</a
100101
>
101102
</div>
102-
<div class="install-block" tabindex="-1">
103-
npm i pdf-creator-node --save
104-
</div>
103+
<div class="install-block" tabindex="-1">npm i pdf-creator-node</div>
104+
<p class="hero__hint">
105+
Node 18+ · See
106+
<a href="https://github.com/hajareshyam/pdf-creator-node/blob/master/readme.md"
107+
>full readme on GitHub</a
108+
>
109+
for TypeScript, validation, and <code>handlebarsHelpers</code>.
110+
</p>
105111
</header>
106112

107113
<section id="quick-start" class="section" aria-labelledby="quick-start-heading">
@@ -118,9 +124,11 @@ <h2 id="quick-start-heading">Quick start</h2>
118124
var html = fs.readFileSync("template.html", "utf8");
119125

120126
var options = {
121-
format: "A3",
122-
orientation: "portrait",
123-
border: "10mm",
127+
pdfChrome: {
128+
layout: { format: "A3", orientation: "portrait", border: "10mm" },
129+
header: { title: "My report" },
130+
footer: { copyright: "© 2026", showPageNumbers: true },
131+
},
124132
};
125133

126134
var document = {
@@ -146,7 +154,7 @@ <h2 id="guide-heading">Step-by-step</h2>
146154
<ol class="steps">
147155
<li class="steps__item">
148156
<div class="steps__title">Install</div>
149-
<div class="install-block">npm i pdf-creator-node --save</div>
157+
<div class="install-block">npm i pdf-creator-node</div>
150158
</li>
151159
<li class="steps__item">
152160
<div class="steps__title">Load the package and read your template</div>
@@ -216,6 +224,42 @@ <h2 id="guide-heading">Step-by-step</h2>
216224
</ol>
217225
</section>
218226

227+
<section id="pdf-chrome" class="section" aria-labelledby="pdf-chrome-heading">
228+
<div class="section__head">
229+
<h2 id="pdf-chrome-heading">Layout, header, footer, copyright</h2>
230+
<p class="section__lede">
231+
Use <code>pdfChrome</code> on the second argument for paper size, repeating
232+
header (<code>title</code> or <code>html</code>), and footer with optional
233+
<code>copyright</code> and page numbers (<code>{{page}}</code> /
234+
<code>{{pages}}</code>). Plain strings are HTML-escaped. Direct
235+
<code>format</code> / <code>header</code> / <code>footer</code> on the same
236+
object override <code>pdfChrome</code>.
237+
</p>
238+
</div>
239+
<pre class="code-block"><code>var options = {
240+
pdfChrome: {
241+
layout: {
242+
format: "A4",
243+
orientation: "portrait",
244+
border: "12mm",
245+
},
246+
header: { title: "Quarterly report" },
247+
footer: {
248+
copyright: "© 2026 My Company",
249+
showPageNumbers: true,
250+
},
251+
},
252+
};
253+
254+
pdf.create(document, options);</code></pre>
255+
<p class="steps__text">
256+
For full control, pass <code>header</code>, <code>footer</code>, and
257+
<code>format</code> in the same options object as
258+
<a href="https://www.npmjs.com/package/html-pdf">html-pdf</a> expects (see
259+
readme).
260+
</p>
261+
</section>
262+
219263
<section id="ifcond" class="section" aria-labelledby="ifcond-heading">
220264
<div class="section__head">
221265
<h2 id="ifcond-heading"><code>ifCond</code> helper</h2>
@@ -234,8 +278,12 @@ <h2 id="ifcond-heading"><code>ifCond</code> helper</h2>
234278
235279
{{/ifCond}}</code></pre>
236280
<aside class="note" role="note">
237-
<strong>Note:</strong> License terms live in the repository (see
238-
footer). Read the full readme on GitHub for more examples.
281+
<strong>Note:</strong> See the
282+
<a href="https://github.com/hajareshyam/pdf-creator-node/blob/master/readme.md"
283+
>readme</a
284+
>
285+
for validation messages, TypeScript, and optional
286+
<code>handlebarsHelpers</code>.
239287
</aside>
240288
</section>
241289

example/index.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
var pdf = require("pdf-creator-node");
2-
// var pdf = require("../index");
32
var fs = require("fs");
43
var path = require("path");
5-
// Read HTML Template
4+
65
var html = fs.readFileSync(path.join(__dirname, "./template.html"), "utf8");
76

7+
/**
8+
* Options use pdfChrome for layout + repeating header/footer (copyright + page numbers).
9+
* You can still set format/header/footer directly on options — they override pdfChrome.
10+
*/
811
var options = {
9-
format: "A3",
10-
orientation: "portrait",
11-
border: "10mm",
12+
pdfChrome: {
13+
layout: {
14+
format: "A3",
15+
orientation: "portrait",
16+
border: "10mm",
17+
},
18+
header: { title: "User list" },
19+
footer: {
20+
copyright: "© pdf-creator-node example",
21+
showPageNumbers: true,
22+
},
23+
},
1224
};
1325

1426
var users = [
15-
{
16-
name: "Shyam",
17-
age: "26",
18-
},
19-
{
20-
name: "Navjot",
21-
age: "26",
22-
},
23-
{
24-
name: "Vitthal",
25-
age: "26",
26-
},
27+
{ name: "Shyam", age: "26" },
28+
{ name: "Navjot", age: "26" },
29+
{ name: "Vitthal", age: "26" },
2730
];
28-
// By default a file is created but you could switch between Buffer and Streams by using "buffer" or "stream" respectively.
31+
32+
// Default is file output. Use type: "buffer" | "stream" for in-memory output.
2933
var document = {
3034
html: html,
31-
data: {
32-
users,
33-
},
35+
data: { users },
3436
path: "./output.pdf",
35-
type: "", // "stream" || "buffer" || "" ("" defaults to pdf)
37+
type: "",
3638
};
3739

3840
pdf
3941
.create(document, options)
40-
.then((res) => {
42+
.then(function (res) {
4143
console.log(res);
4244
})
43-
.catch((error) => {
45+
.catch(function (error) {
4446
console.error(error);
4547
});

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pdf-creator-node",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "node pdf creator",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ await pdf.create(document, options);
6363
- **Buffer:** `type: "buffer"`.
6464
- **Stream:** `type: "stream"`.
6565

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+
6688
### Optional Handlebars helpers
6789

6890
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.

src/createPdf.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import Handlebars from "handlebars";
22
import pdf from "html-pdf";
3-
import type { CreateOptions } from "html-pdf";
43
import type { FileInfo } from "html-pdf";
4+
import { mergePdfCreateOptions } from "./pdfChrome";
55
import { registerHandlebarsHelpers } from "./registerHandlebarsHelpers";
66
import type { PdfCreateOptions, PdfDocument } from "./types";
77
import { validatePdfDocument } from "./validation";
88

9-
function stripHtmlPdfOptions(options: PdfCreateOptions): CreateOptions {
10-
const { handlebarsHelpers: _h, ...rest } = options;
11-
return rest;
12-
}
13-
149
function renderHtml(document: PdfDocument, options: PdfCreateOptions): string {
1510
const hb = Handlebars.create();
1611
registerHandlebarsHelpers(hb);
@@ -50,7 +45,7 @@ export function create(
5045
return;
5146
}
5247

53-
const pdfOptions = stripHtmlPdfOptions(options);
48+
const pdfOptions = mergePdfCreateOptions(options);
5449
const pdfPromise = pdf.create(html, pdfOptions);
5550

5651
switch (document.type) {

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ import { create } from "./createPdf";
88
registerHandlebarsHelpers();
99

1010
export { create };
11+
export { buildPdfChrome } from "./pdfChrome";
1112
export type {
1213
Document,
1314
IfCondOptions,
15+
PdfChromeOptions,
1416
PdfCreateOptions,
1517
PdfDocument,
1618
PdfDocumentBuffer,
1719
PdfDocumentFile,
1820
PdfDocumentStream,
21+
PdfFooterConfig,
22+
PdfHeaderConfig,
23+
PdfLayout,
1924
} from "./types";
2025

2126
const api = { create };

0 commit comments

Comments
 (0)