pagyra-js 0.0.17 → 0.0.19

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/README.md CHANGED
@@ -58,10 +58,10 @@ const pdfBytes = await renderHtmlToPdf({
58
58
  fs.writeFileSync('output.pdf', Buffer.from(pdfBytes));
59
59
  ```
60
60
 
61
- ### Advanced Example with Custom Fonts
62
-
63
- ```typescript
64
- import { renderHtmlToPdf } from 'pagyra-js';
61
+ ### Advanced Example with Custom Fonts
62
+
63
+ ```typescript
64
+ import { renderHtmlToPdf } from 'pagyra-js';
65
65
 
66
66
  const pdfBytes = await renderHtmlToPdf({
67
67
  html: `
@@ -109,12 +109,56 @@ const pdfBytes = await renderHtmlToPdf({
109
109
  }
110
110
  ]
111
111
  }
112
- });
113
- ```
114
-
115
- ## API Reference
116
-
117
- ### Main Functions
112
+ });
113
+ ```
114
+
115
+ ### Header and Footer Example
116
+
117
+ ```typescript
118
+ import { renderHtmlToPdf } from 'pagyra-js';
119
+
120
+ const headerHtml = `
121
+ <div style="border-bottom: 1px solid #ccc; padding-bottom: 8px;">
122
+ <img
123
+ src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADUlEQVR42mP8/5+hHgAHggJ/P95syQAAAABJRU5ErkJggg=="
124
+ alt="logo"
125
+ style="height: 48px; width: 48px;"
126
+ />
127
+ <span>My Report</span>
128
+ </div>
129
+ `;
130
+
131
+ const footerHtml = `
132
+ <div style="border-top: 1px solid #ccc; padding-top: 8px; font-size: 12px;">
133
+ Page {{pageNumber}} / {{totalPages}}
134
+ </div>
135
+ `;
136
+
137
+ const pdfBytes = await renderHtmlToPdf({
138
+ html: '<p>Main content goes here.</p>',
139
+ css: 'body { font-family: Arial; }',
140
+ headerFooter: {
141
+ headerHtml,
142
+ footerHtml,
143
+
144
+ // Optional: if omitted, Pagyra auto-measures header/footer content height.
145
+ // maxHeaderHeightPx: 80,
146
+ // maxFooterHeightPx: 40,
147
+
148
+ // Optional: draw header/footer over the content instead of under it.
149
+ // layerMode: 'over'
150
+ }
151
+ });
152
+ ```
153
+
154
+ Notes:
155
+ - `headerHtml` and `footerHtml` are full HTML fragments (can include images, including base64).
156
+ - If `maxHeaderHeightPx` / `maxFooterHeightPx` are not provided, Pagyra auto-computes them from rendered header/footer content.
157
+ - You can also use per-page variants: `headerFirstHtml`, `headerEvenHtml`, `headerOddHtml` (same for footer).
158
+
159
+ ## API Reference
160
+
161
+ ### Main Functions
118
162
 
119
163
  #### `renderHtmlToPdf(options: RenderHtmlOptions): Promise<Uint8Array>`
120
164
 
@@ -137,9 +181,18 @@ Converts HTML to PDF and returns the PDF as a Uint8Array.
137
181
  - `debugCats`: Debug categories (optional)
138
182
  - `fontConfig`: Font configuration (optional, loads built-in fonts by default)
139
183
  - `resourceBaseDir`: Base directory for resource resolution (optional)
140
- - `assetRootDir`: Asset root directory (optional)
141
- - `headerFooter`: Header/footer configuration (optional)
142
- - `environment`: Environment abstraction (Node/browser, optional - defaults to Node environment)
184
+ - `assetRootDir`: Asset root directory (optional)
185
+ - `headerFooter`: Header/footer configuration (optional)
186
+ - `environment`: Environment abstraction (Node/browser, optional - defaults to Node environment)
187
+
188
+ `headerFooter` accepts:
189
+ - `headerHtml`, `footerHtml`: default header/footer HTML
190
+ - `headerFirstHtml`, `footerFirstHtml`: first-page variants
191
+ - `headerEvenHtml`, `footerEvenHtml`: even-page variants
192
+ - `headerOddHtml`, `footerOddHtml`: odd-page variants
193
+ - `maxHeaderHeightPx`, `maxFooterHeightPx`: reserved space in pixels (optional, auto-measured if omitted)
194
+ - `layerMode`: `"under"` (default) or `"over"`
195
+ - `clipOverflow`, `fontFamily`, `placeholders` (advanced)
143
196
 
144
197
  **Note:** While the TypeScript interface requires all parameters, in practice only `html` is truly mandatory. The playground server demonstrates how to compute reasonable defaults for other parameters using helper functions like `sanitizeDimension()` and `resolvePageMarginsPx()`.
145
198