p3x-html-pdf 2025.4.125 → 2025.4.126
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 +74 -11
- package/package.json +1 -1
- package/test-output.pdf +0 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
# 📃 Generates PDF from HTML with custom headers and footers with wkhtmltopdf v2025.4.
|
|
9
|
+
# 📃 Generates PDF from HTML with custom headers and footers with wkhtmltopdf v2025.4.126
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -69,7 +69,7 @@ const { generate } = require('p3x-html-pdf');
|
|
|
69
69
|
## 🛠️ Features
|
|
70
70
|
|
|
71
71
|
- 📜 **Custom Headers and Footers**: Create professional headers and footers with dynamic placeholders.
|
|
72
|
-
-
|
|
72
|
+
- 🔀 **Flexible Page Settings**: Set paper size, orientation, margins, and more.
|
|
73
73
|
- ⚡ **Async/Await Support**: Fully compatible with modern JavaScript workflows.
|
|
74
74
|
- 📊 **Dynamic Tables and Content**: Generate tables and other dynamic HTML content easily.
|
|
75
75
|
|
|
@@ -96,7 +96,7 @@ const path = require('path');
|
|
|
96
96
|
<h1>Header Content</h1>
|
|
97
97
|
</div>
|
|
98
98
|
<div id="p3x-footer" data-height="15mm">
|
|
99
|
-
<p>Page
|
|
99
|
+
<p>Page \${page} of \${pages}</p>
|
|
100
100
|
</div>
|
|
101
101
|
<div>
|
|
102
102
|
<h2>Content</h2>
|
|
@@ -157,25 +157,24 @@ const path = require('path');
|
|
|
157
157
|
- **jquery**: The latest that works with webkit is jQuery v1.12.4
|
|
158
158
|
- **javascriptDelay**: The delay before the PDF is generated as default is 1000 ms.
|
|
159
159
|
|
|
160
|
-
For more options, check the official [wkhtmltopdf usage guide](https://wkhtmltopdf.org/usage/wkhtmltopdf.txt).
|
|
160
|
+
For more options, check the official [wkhtmltopdf usage guide](https://wkhtmltopdf.org/usage/wkhtmltopdf.txt).
|
|
161
|
+
|
|
162
|
+
Unfortunately the version latest HTTS is not working, so it is better to use inline images or using HTTP as that is dated but with HTTP in local filesystem is perfect.
|
|
161
163
|
|
|
162
164
|
---
|
|
163
165
|
|
|
164
166
|
## 🌟 Placeholders
|
|
165
167
|
|
|
166
|
-
You can use placeholders in your HTML for dynamic data:
|
|
168
|
+
You can use placeholders in your HTML for dynamic data (only these, but it is enough, the rest you can generate in HTML):
|
|
167
169
|
|
|
168
170
|
- `${page}`: Current page.
|
|
169
171
|
- `${pages}`: Total pages.
|
|
170
|
-
- `${date}`: Current date.
|
|
171
|
-
- `${isodate}`: ISO date format.
|
|
172
|
-
- `${time}`: Current time.
|
|
173
172
|
|
|
174
173
|
Example:
|
|
175
174
|
|
|
176
175
|
```html
|
|
177
176
|
<div id="p3x-footer" data-height="15mm">
|
|
178
|
-
<p>Page ${page} of ${pages}
|
|
177
|
+
<p>Page ${page} of ${pages}</p>
|
|
179
178
|
</div>
|
|
180
179
|
```
|
|
181
180
|
|
|
@@ -204,7 +203,71 @@ Download the binary manually and place it there:
|
|
|
204
203
|
## 🖼️ Example Output
|
|
205
204
|
|
|
206
205
|
Check out an example output PDF:
|
|
207
|
-
[Example PDF](https://cdn.corifeus.com/git/html-pdf/test-output.pdf).
|
|
206
|
+
[Example PDF](https://cdn.corifeus.com/git/html-pdf/assets/test-output.pdf).
|
|
207
|
+
|
|
208
|
+

|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 🔬 Legacy Rendering with Webkit
|
|
212
|
+
|
|
213
|
+
This library uses `wkhtmltopdf`, which relies on an older version of Webkit. As such, it does not support modern CSS features like `flexbox`. Instead, older solutions such as `float` and `table`-based layouts must be used for alignment. While these approaches are not modern, they are efficient and compatible with the rendering engine.
|
|
214
|
+
|
|
215
|
+
For instance, the following layout works seamlessly:
|
|
216
|
+
|
|
217
|
+
```html
|
|
218
|
+
<div id="p3x-header" data-height="40mm">
|
|
219
|
+
<div style="width: 100%; padding: 0px; display: table;">
|
|
220
|
+
<div style="display: table-cell; vertical-align: middle;">
|
|
221
|
+
<img src="http://cdn.corifeus.com/assets/png/patrikx3.png" alt="Header Logo" style="height:40mm; margin:0;"/>
|
|
222
|
+
</div>
|
|
223
|
+
<div style="display: table-cell; vertical-align: middle; text-align: right; width: 100%;">
|
|
224
|
+
<h1 style="margin: 0; font-size: 20px; color: #333;">P3X HTML Invoice</h1>
|
|
225
|
+
<p style="margin: 5px 0 0; font-size: 14px; color: #555;">Generated: 2023-10-01</p>
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
</div>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Node.js Test Example
|
|
234
|
+
|
|
235
|
+
The `node ./test/test.js` script demonstrates how to generate the example PDF:
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
const { generate } = require('../src/index');
|
|
239
|
+
const path = require('path');
|
|
240
|
+
const fs = require('fs');
|
|
241
|
+
|
|
242
|
+
(async () => {
|
|
243
|
+
try {
|
|
244
|
+
const outputPath = path.resolve(__dirname, '..', 'test-output.pdf');
|
|
245
|
+
if (fs.existsSync(outputPath)) {
|
|
246
|
+
fs.unlinkSync(outputPath);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const options = {
|
|
250
|
+
settings: {
|
|
251
|
+
save: true,
|
|
252
|
+
template: {
|
|
253
|
+
format: 'A4',
|
|
254
|
+
orientation: 'portrait',
|
|
255
|
+
marginLeft: 10,
|
|
256
|
+
marginRight: 10,
|
|
257
|
+
},
|
|
258
|
+
html: '<h1>Hello PDF</h1>',
|
|
259
|
+
},
|
|
260
|
+
title: 'Test PDF',
|
|
261
|
+
saveFile: outputPath,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
await generate(options);
|
|
265
|
+
console.log('PDF generated!');
|
|
266
|
+
} catch (error) {
|
|
267
|
+
console.error('Error:', error);
|
|
268
|
+
}
|
|
269
|
+
})();
|
|
270
|
+
```
|
|
208
271
|
|
|
209
272
|
---
|
|
210
273
|
|
|
@@ -316,7 +379,7 @@ All my domains, including [patrikx3.com](https://patrikx3.com), [corifeus.eu](ht
|
|
|
316
379
|
---
|
|
317
380
|
|
|
318
381
|
|
|
319
|
-
[**P3X-HTML-PDF**](https://corifeus.com/html-pdf) Build v2025.4.
|
|
382
|
+
[**P3X-HTML-PDF**](https://corifeus.com/html-pdf) Build v2025.4.126
|
|
320
383
|
|
|
321
384
|
[](https://www.npmjs.com/package/p3x-html-pdf) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [](https://www.patrikx3.com/en/front/contact) [](https://www.facebook.com/corifeus.software)
|
|
322
385
|
|
package/package.json
CHANGED
package/test-output.pdf
DELETED
|
Binary file
|