p3x-html-pdf 2025.4.153 → 2025.4.154

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
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- # 📃 Generates PDF from HTML with custom headers and footers with wkhtmltopdf v2025.4.153
9
+ # 📃 Generates PDF from HTML with custom headers and footers with wkhtmltopdf v2025.4.154
10
10
 
11
11
 
12
12
 
@@ -37,7 +37,7 @@ v22.13.0
37
37
 
38
38
  **p3x-html-pdf** is a Node.js package that generates PDFs from HTML with custom headers and footers using `wkhtmltopdf`. It is a robust tool for creating professional-grade PDFs with features like:
39
39
 
40
- - 📜 **Dynamic Headers and Footers**: Add placeholders for page numbers.
40
+ - 📜 **Dynamic Headers and Footers**: Add placeholders for page numbers, dates, and more.
41
41
  - 🛠️ **Customizable Layouts**: Configure margins, orientation, and paper size.
42
42
  - ⚡ **Async/Await Support**: Modern JavaScript compatibility for efficient workflows.
43
43
  - 🔄 **Dynamic Content**: Render data-driven tables and content dynamically.
@@ -160,17 +160,28 @@ You can use placeholders in your HTML for dynamic data (only these, but it is en
160
160
 
161
161
  - `${page}`: Current page.
162
162
  - `${pages}`: Total pages.
163
-
164
- Example:
163
+ - `${frompage}`: The starting page of the current section.
164
+ - `${topage}`: The ending page of the current section.
165
+ - `${webpage}`: The URL of the web page (if applicable).
166
+ - `${section}`: The name of the current section.
167
+ - `${subsection}`: The name of the current subsection.
168
+ - `${date}`: The current date in a localized format.
169
+ - `${isodate}`: The current date in ISO 8601 format.
170
+ - `${time}`: The current time.
171
+ - `${title}`: The document title.
172
+ - `${doctitle}`: The title of the document as defined in metadata.
173
+ - `${sitepage}`: Current site page number (specific context).
174
+ - `${sitepages}`: Total number of site pages (specific context).
175
+
176
+ ### Example
165
177
 
166
178
  ```html
167
- <div id="p3x-footer" data-height="15mm">
179
+ <div id="p3x-footer" data-height="10mm">
168
180
  <p>Page ${page} of ${pages}</p>
169
181
  </div>
170
182
  ```
171
183
 
172
184
  The `p3x-footer` and `p3x-header` should not have any styles other than `id` and `data-height`.
173
-
174
185
  ---
175
186
 
176
187
  ## 📊 Advanced Features
@@ -354,7 +365,7 @@ All my domains, including [patrikx3.com](https://patrikx3.com), [corifeus.eu](ht
354
365
  ---
355
366
 
356
367
 
357
- [**P3X-HTML-PDF**](https://corifeus.com/html-pdf) Build v2025.4.153
368
+ [**P3X-HTML-PDF**](https://corifeus.com/html-pdf) Build v2025.4.154
358
369
 
359
370
  [![NPM](https://img.shields.io/npm/v/p3x-html-pdf.svg)](https://www.npmjs.com/package/p3x-html-pdf) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software)
360
371
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "p3x-html-pdf",
3
- "version": "2025.4.153",
3
+ "version": "2025.4.154",
4
4
  "corifeus": {
5
5
  "prefix": "p3x-",
6
6
  "publish": true,
package/src/index.js CHANGED
@@ -111,6 +111,18 @@ const generate = async (options) => {
111
111
  const lodashTemplateHack = `
112
112
  item = item.replace(/\\$\{page}/g, vars.page);
113
113
  item = item.replace(/\\$\{pages}/g, vars.pages);
114
+ item = item.replace(/\\$\{frompage}/g, vars.frompage);
115
+ item = item.replace(/\\$\{topage}/g, vars.topage);
116
+ item = item.replace(/\\$\{webpage}/g, vars.webpage);
117
+ item = item.replace(/\\$\{section}/g, vars.section);
118
+ item = item.replace(/\\$\{subsection}/g, vars.subsection);
119
+ item = item.replace(/\\$\{date}/g, vars.date);
120
+ item = item.replace(/\\$\{isodate}/g, vars.isodate);
121
+ item = item.replace(/\\$\{time}/g, vars.time);
122
+ item = item.replace(/\\$\{title}/g, vars.title);
123
+ item = item.replace(/\\$\{doctitle}/g, vars.doctitle);
124
+ item = item.replace(/\\$\{sitepage}/g, vars.sitepage);
125
+ item = item.replace(/\\$\{sitepages}/g, vars.sitepages);
114
126
  item = item.replace(/\\$\{qr}/g, qr);
115
127
 
116
128
  `;
@@ -145,10 +157,18 @@ var qr = ${JSON.stringify(mainsSettings.settings.qr)};
145
157
  // console.debug('html', html)
146
158
  // console.debug('header', header)
147
159
 
148
- tmpHtmlPath = await utils.fs.ensureTempFile(html, 'html')
160
+ if (save) {
161
+ tmpPdfPath = saveFile;
162
+ tmpHtmlPath = `${saveFile}.html`;
163
+ await utils.fs.ensureFile(tmpHtmlPath, html);
164
+ } else {
165
+ tmpHtmlPath = await utils.fs.ensureTempFile(html, 'html')
166
+ tmpPdfPath = await utils.fs.tempFileName('pdf');
167
+ }
168
+
149
169
  tmpHtmlPathHeader = await utils.fs.ensureTempFile(header, 'html')
150
170
  tmpHtmlPathFooter = await utils.fs.ensureTempFile(footer, 'html')
151
- tmpPdfPath = await utils.fs.tempFileName('pdf');
171
+
152
172
  //console.debug('header', footer)
153
173
  //console.debug('footer', footer)
154
174
  //console.debug('html', footer)
@@ -189,10 +209,8 @@ var qr = ${JSON.stringify(mainsSettings.settings.qr)};
189
209
 
190
210
  await utils.childProcess.exec(generatePdfCommand, debug);
191
211
 
192
- if (save) {
193
- await fsExtra.move(tmpPdfPath, saveFile)
194
- } else {
195
- return fs.readFile(tmpPdfPath);
212
+ if (!save) {
213
+ return await fs.readFile(tmpPdfPath);
196
214
  }
197
215
  } finally {
198
216
  if (tmpHtmlPath !== undefined) {
package/test/test.js CHANGED
@@ -46,7 +46,9 @@ const fs = require('fs');
46
46
  </div>
47
47
  </div>
48
48
  <div id="p3x-footer" data-height="10mm" >
49
- <div style="text-align: right; font-size: 12px; color: #777;">Page \${page} of \${pages}</div>
49
+ <div style="text-align: right; font-size: 12px; color: #777;">
50
+ Page \${page} of \${pages}
51
+ </div>
50
52
  </div>
51
53
  <div>
52
54
  <h2 style="color: #222;">Invoice Content</h2>
@@ -102,7 +104,7 @@ const fs = require('fs');
102
104
  `,
103
105
  },
104
106
  title: 'P3X-HTML-PDF Detailed Invoice',
105
- debug: false,
107
+ debug: true,
106
108
  saveFile: outputPath,
107
109
  };
108
110