marqius-wkhtmltopdf 0.12.13 → 0.12.14

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
@@ -1,6 +1,51 @@
1
- # marqius-wkhtmltopdf: wkhtmltopdf for Node.js
1
+ # wkhtmltopdf for Node.js: marqius-wkhtmltopdf for the wkhtmltopdf and wkhtmltoimage packages
2
2
 
3
- **marqius-wkhtmltopdf is the maintained drop-in replacement for wkhtmltopdf, as an npm package.** `npm install` it, give your library its path in one line, and the `wkhtmltopdf` and `wkhtmltoimage` packages keep making PDFs and pictures from your HTML. It runs on Linux (x64 and arm64, glibc and musl, including Debian 13, Ubuntu 24.04 and Alpine), Apple silicon Macs and Windows (x64).
3
+ [![npm](https://img.shields.io/npm/v/marqius-wkhtmltopdf)](https://www.npmjs.com/package/marqius-wkhtmltopdf)
4
+
5
+ **marqius-wkhtmltopdf is the maintained drop-in replacement for wkhtmltopdf, installed with npm.** Install it with one command, give your library its path in one line, and the `wkhtmltopdf` and `wkhtmltoimage` packages turn your HTML into PDFs and pictures as before. It prints Arabic, Hebrew, Hindi, Thai, Chinese, Japanese and Korean as well as English, on Linux, Mac and Windows.
6
+
7
+ - **One command to install.** No apt packages, no libssl 1.1, no X server, no Qt, and no install script: npm installs the program for your computer.
8
+ - **Your templates stay as they are.** The same HTML, the same options, the same package.
9
+ - **Many languages, even on one page.** Arabic and Hebrew from right to left, Indian and Asian scripts, all as text you can search and copy.
10
+ - **Fast.** A one-page invoice takes a few milliseconds.
11
+ - **Tested in public.** Every version is tested with the `wkhtmltopdf` and `wkhtmltoimage` packages on Linux, macOS and Windows before it is published.
12
+
13
+ ## Make your first PDF in two minutes
14
+
15
+ **1. Install** the package and `wkhtmltopdf`, the most used Node package for wkhtmltopdf. Run this in your project, or in an empty folder:
16
+
17
+ <!-- quickstart -->
18
+ ```bash
19
+ npm install marqius-wkhtmltopdf wkhtmltopdf
20
+ ```
21
+
22
+ **2. Save** this as `invoice.js`:
23
+
24
+ <!-- example: quickstart invoice.js -->
25
+ ```js
26
+ const wkhtmltopdf = require("wkhtmltopdf");
27
+ wkhtmltopdf.command = require("marqius-wkhtmltopdf").path;
28
+
29
+ wkhtmltopdf("<h1>Invoice 42</h1><p>Thank you for your order.</p>", { output: "invoice.pdf" });
30
+ ```
31
+
32
+ **3. Run** it, then open `invoice.pdf`:
33
+
34
+ <!-- run -->
35
+ ```bash
36
+ node invoice.js
37
+ ```
38
+
39
+ That's it. Next, connect your code, or [print other languages](#which-languages-can-it-print).
40
+
41
+ ## What do I change in my code?
42
+
43
+ | You use | What to do |
44
+ |---|---|
45
+ | The `wkhtmltopdf` package | [Set `wkhtmltopdf.command`](#how-do-i-use-it-with-the-wkhtmltopdf-package) |
46
+ | The `wkhtmltoimage` package | [Call `setCommand`](#how-do-i-make-pictures-with-wkhtmltoimage) |
47
+ | Your own `child_process` call | [Run the path it gives](#how-do-i-run-wkhtmltopdf-from-node-without-a-library) |
48
+ | ES modules or TypeScript | [Import it](#can-i-use-it-from-an-es-module-or-typescript) |
4
49
 
5
50
  ## How do I install wkhtmltopdf with npm?
6
51
 
@@ -38,15 +83,97 @@ wkhtmltoimage.setCommand(require("marqius-wkhtmltopdf").imagePath);
38
83
  wkhtmltoimage.generate("<h1>Invoice 42</h1>", { output: "invoice.jpg" });
39
84
  ```
40
85
 
41
- ## Can I use it from an ES module?
86
+ ## How do I run wkhtmltopdf from Node without a library?
87
+
88
+ Run the path as you would run wkhtmltopdf, with `execFile`, `spawn` or `execFileSync`. A `-` in place of the page reads the HTML from the input:
89
+
90
+ <!-- example: child_process -->
91
+ ```js
92
+ const { execFileSync } = require("child_process");
93
+ const { path } = require("marqius-wkhtmltopdf");
94
+
95
+ execFileSync(path, ["-", "invoice.pdf"], { input: "<h1>Invoice 42</h1>" });
96
+ ```
97
+
98
+ ## Can I use it from an ES module or TypeScript?
42
99
 
43
- Yes. `marqius.path` is the same path:
100
+ Yes. The package comes with its own types, and `marqius.path` is the same path:
44
101
 
45
102
  <!-- example: import -->
46
103
  ```js
47
104
  import marqius from "marqius-wkhtmltopdf";
48
105
  ```
49
106
 
107
+ ## Which languages can it print?
108
+
109
+ All of these, even on one page. Each one is tested on real invoices, letters and receipts, and the PDF keeps the words as text, so you can search and copy them.
110
+
111
+ | Language | On a Linux server | On a Mac or Windows |
112
+ |---|---|---|
113
+ | English, French, German, Spanish and other languages in Latin letters; Greek; Russian | Works with the fonts most servers have | Works |
114
+ | Arabic and Hebrew, from right to left | Works: the fonts are built in | Works |
115
+ | Hindi and Thai | Install `fonts-noto-core` | Works |
116
+ | Chinese, Japanese and Korean | Install `fonts-noto-cjk` | Works |
117
+
118
+ On Debian or Ubuntu, this one line installs the fonts for every language above:
119
+
120
+ <!-- fonts: debian -->
121
+ ```bash
122
+ sudo apt-get update && sudo apt-get install -y fonts-noto-core fonts-noto-cjk
123
+ ```
124
+
125
+ In a Dockerfile, put the same line after `RUN`, without `sudo`. On Alpine, Fedora, Red Hat or Arch, the program tells you the line for your system ([see below](#why-do-letters-show-as-boxes-or-blanks-in-my-pdf)).
126
+
127
+ Then one invoice can carry them all, here with the `wkhtmltopdf` package:
128
+
129
+ <!-- example: languages -->
130
+ ```js
131
+ const wkhtmltopdf = require("wkhtmltopdf");
132
+ wkhtmltopdf.command = require("marqius-wkhtmltopdf").path;
133
+
134
+ const html = `<!doctype html>
135
+ <meta charset="utf-8">
136
+ <h1>Invoice 42</h1>
137
+ <p lang="ar" dir="rtl">فاتورة 42</p>
138
+ <p lang="he" dir="rtl">חשבונית 42</p>
139
+ <p lang="hi">चालान 42</p>
140
+ <p lang="th">ใบแจ้งหนี้ 42</p>
141
+ <p lang="zh">发票 42</p>
142
+ <p lang="ja">請求書 42</p>
143
+ <p lang="ko">청구서 42</p>
144
+ `;
145
+
146
+ wkhtmltopdf(html, { output: "invoice.pdf" });
147
+ ```
148
+
149
+ For a page all in Arabic or Hebrew, put `dir="rtl"` on its `<html>` tag. The page then reads from the right, and its tables and lists turn to match.
150
+
151
+ ## Why do letters show as boxes or blanks in my PDF?
152
+
153
+ The computer that makes the PDF has no font for them. On Linux, install the fonts [above](#which-languages-can-it-print). To see what is missing, convert your page with the program itself:
154
+
155
+ <!-- check -->
156
+ ```bash
157
+ npx marqius-wkhtmltopdf page.html page.pdf
158
+ ```
159
+
160
+ It names each letter it could not print, then gives the one line that installs fonts for them on your system: `apt-get` on Debian and Ubuntu, `apk` on Alpine, `dnf` on Fedora and Red Hat, `pacman` on Arch.
161
+
162
+ ## Why can't I search or copy Arabic, Chinese or Hindi text in my wkhtmltopdf PDF?
163
+
164
+ wkhtmltopdf often stores these scripts as shapes, not words. The public parity suite prints the same pages with both programs:
165
+
166
+ - **Arabic:** from wkhtmltopdf's invoice, 2 of its 56 words read back as written; from marqius-wkhtmltopdf's, 48.
167
+ - **Hebrew:** wkhtmltopdf splits many words into single letters (28 of 48 read back); marqius-wkhtmltopdf gives back 43.
168
+ - **Chinese:** wkhtmltopdf puts look-alike signs in place of some characters, so a search for the company's name finds nothing. marqius-wkhtmltopdf keeps the real characters.
169
+ - **Hindi and Thai:** wkhtmltopdf loses letters and splits off marks. marqius-wkhtmltopdf's text reads back clean.
170
+
171
+ The pages themselves look the same. [See every page and score](https://github.com/marqiushq/wkhtmltopdf-parity).
172
+
173
+ ## Why are accented letters garbled, like é for é?
174
+
175
+ Your page does not say that it is UTF-8, so wkhtmltopdf reads it as an old Western character set. marqius-wkhtmltopdf prints é, € and ü as written anyway. To make every program agree, put `<meta charset="utf-8">` at the top of your page.
176
+
50
177
  ## Why do I get "wkhtmltopdf: command not found"?
51
178
 
52
179
  The `wkhtmltopdf` package runs a program called `wkhtmltopdf` through bash, and your machine has none. Install this package and set `wkhtmltopdf.command` to its path, as shown above.
@@ -55,23 +182,35 @@ The `wkhtmltopdf` package runs a program called `wkhtmltopdf` through bash, and
55
182
 
56
183
  Your wkhtmltopdf was built for an older system. It needs OpenSSL 1.1, which Debian 13 and Ubuntu 24.04 no longer include. marqius-wkhtmltopdf needs no system libraries, so it runs there as it is.
57
184
 
58
- ## Which systems does marqius-wkhtmltopdf run on?
185
+ ## Is it faster than wkhtmltopdf?
186
+
187
+ Yes. The public parity suite converts 86 documents with both programs on the same machine. marqius-wkhtmltopdf is 35 times faster, or 5 times faster with wkhtmltopdf's 200 ms wait for scripts turned off for both. On Linux, a one-page invoice takes 5 to 7 milliseconds. [See the results](https://github.com/marqiushq/wkhtmltopdf-parity).
188
+
189
+ ## Will my PDFs look the same as with wkhtmltopdf?
190
+
191
+ Almost always. Of the parity suite's 86 documents, 64 come out the same, and 16 differ only in small details of appearance. Each difference is listed with its reason. To check your own templates, make a PDF with each program and compare them:
192
+
193
+ ```bash
194
+ npx marqius-wkhtmltopdf compare old.pdf new.pdf
195
+ ```
196
+
197
+ ## Which systems does it run on?
59
198
 
60
199
  It runs on:
61
200
 
62
- - Linux on x64 and arm64, with glibc or musl (so Alpine too);
201
+ - Linux on x64 and arm64, with glibc or musl, so Debian 13, Ubuntu 24.04 and Alpine too;
63
202
  - Macs with Apple silicon;
64
203
  - Windows on x64.
65
204
 
66
- npm installs the right package for each. It needs no X server, Qt or system libraries. In a slim or Alpine image without fonts, the program says so and prints the one line that installs them.
205
+ npm installs the right package for each, a download of about 10 MB. It needs no X server, Qt or system libraries. In a slim or Alpine image without fonts, the program says so and prints the one line that installs them. There is no build for Macs with Intel chips: there, `require` says so.
67
206
 
68
207
  ## Is marqius-wkhtmltopdf free?
69
208
 
70
209
  You can try it free for 30 days. Personal, teaching and open-source use is free with a [Community licence](https://marqius.com/wkhtmltopdf-buy/#community): sign in with Google and your free key is waiting in your account.
71
210
 
72
- Anything done by or for a business, including internal tools and client work, needs Starter or above once the trial ends. Starter is $290 USD a year for organisations of up to 10 people, and Business $990 USD a year, plus applicable taxes.
211
+ Anything done by or for a business, including internal tools and client work, needs a paid plan once the trial ends. [See the plans and prices](https://marqius.com/licence/marqius-wkhtmltopdf).
73
212
 
74
- Your PDFs never stop. Without a licence after the trial, each page carries one line, "Prepared by Marqius, Purchase Licence". [Plans and licences](https://marqius.com/licence/marqius-wkhtmltopdf) · [Licence terms](https://marqius.com/wkhtmltopdf/licence-agreement/)
213
+ Your PDFs never stop. Without a licence after the trial, each page carries one line, "Prepared by Marqius, Purchase Licence". [Licence terms](https://marqius.com/wkhtmltopdf/licence-agreement/)
75
214
 
76
215
  ## How do I add my licence key?
77
216
 
@@ -81,16 +220,19 @@ Set the `MARQIUS_LICENCE` environment variable to your licence; that is the way
81
220
 
82
221
  Yes. The `wkhtmltopdf` package passes its own test suite with marqius-wkhtmltopdf, all 5 of its tests. The results are public: [wkhtmltopdf library tests](https://github.com/marqiushq/wkhtmltopdf-library-tests).
83
222
 
84
- Before each version of this package is published, [its workflow](https://github.com/marqiushq/marqius-wkhtmltopdf-node/blob/main/.github/workflows/release.yml) installs it with npm and runs the examples on this page on Linux (x64 and arm64), macOS and Windows.
223
+ Before each version of this package is published, [its workflow](https://github.com/marqiushq/marqius-wkhtmltopdf-node/blob/main/.github/workflows/release.yml) installs it with npm and runs the examples on this page, the eight-language invoice among them, on Linux (x64 and arm64), macOS and Windows.
85
224
 
86
225
  ## How do I update it?
87
226
 
88
- Each version of this package carries the marqius-wkhtmltopdf release with the same number. To move to the newest:
227
+ Run this in your project. It installs the newest version with your project's package manager: npm, pnpm, yarn or bun:
89
228
 
229
+ <!-- update -->
90
230
  ```bash
91
- npm install marqius-wkhtmltopdf@latest
231
+ npx marqius-wkhtmltopdf update
92
232
  ```
93
233
 
234
+ `npm install marqius-wkhtmltopdf@latest` does the same. Each version of this package carries the marqius-wkhtmltopdf release with the same number, after testing it.
235
+
94
236
  ## What else does the program do?
95
237
 
96
238
  `npx marqius-wkhtmltopdf` runs it under its own name:
@@ -99,4 +241,8 @@ npm install marqius-wkhtmltopdf@latest
99
241
  - `npx marqius-wkhtmltopdf compare old.pdf new.pdf` lists every difference between a PDF made by wkhtmltopdf and one made by marqius-wkhtmltopdf;
100
242
  - `npx marqius-wkhtmltopdf install` gives it the names `wkhtmltopdf` and `wkhtmltoimage` for everything on a server, with the rights to write to `/usr/local/bin`.
101
243
 
244
+ ## Where do I get help?
245
+
246
+ Write to hello@marqius.com, or [open an issue](https://github.com/marqiushq/marqius-wkhtmltopdf-node/issues). Send the page that prints differently from wkhtmltopdf if you can.
247
+
102
248
  This package's own JavaScript files are under the MIT licence: [LICENSE.md](LICENSE.md).
@@ -1,8 +1,111 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  // marqius-wkhtmltopdf under its own name (npx marqius-wkhtmltopdf): help, licence, compare,
4
- // install and wkhtmltopdf's command line. Commercial software with a 30-day free trial.
4
+ // install and wkhtmltopdf's command line. `update` updates this package itself, in the project
5
+ // that depends on it, with that project's package manager (npm, pnpm, yarn or bun).
6
+ // Commercial software with a 30-day free trial.
5
7
  const { spawnSync } = require("child_process");
8
+ const fs = require("fs");
9
+ const path = require("path");
10
+
11
+ const NAME = "marqius-wkhtmltopdf";
12
+ const windows = process.platform === "win32";
13
+
14
+ function readJson(file) {
15
+ try {
16
+ return JSON.parse(fs.readFileSync(file, "utf8"));
17
+ } catch (e) {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ // The project that depends on this package: the first folder up, outside node_modules, whose
23
+ // package.json names it. With which section names it.
24
+ function project(pkgDir) {
25
+ for (let dir = path.dirname(pkgDir); dir !== path.dirname(dir); dir = path.dirname(dir)) {
26
+ if (dir.split(path.sep).includes("node_modules")) continue;
27
+ const json = readJson(path.join(dir, "package.json"));
28
+ if (!json) continue;
29
+ for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
30
+ if (json[section] && json[section][NAME]) return { dir, section };
31
+ }
32
+ }
33
+ return null;
34
+ }
35
+
36
+ // The package manager the project uses, by its lock file, else by what started this command.
37
+ function manager(dir) {
38
+ const has = (f) => fs.existsSync(path.join(dir, f));
39
+ if (has("pnpm-lock.yaml")) return "pnpm";
40
+ if (has("yarn.lock")) return "yarn";
41
+ if (has("bun.lock") || has("bun.lockb")) return "bun";
42
+ if (has("package-lock.json") || has("npm-shrinkwrap.json")) return "npm";
43
+ const agent = (process.env.npm_config_user_agent || "").split("/")[0];
44
+ return ["pnpm", "yarn", "bun"].includes(agent) ? agent : "npm";
45
+ }
46
+
47
+ function run(command, args, cwd) {
48
+ // (npm, pnpm and yarn are .cmd files on Windows, which only a shell starts)
49
+ const r = spawnSync(command, args, { cwd, stdio: "inherit", shell: windows });
50
+ if (r.error) {
51
+ console.error(`marqius-wkhtmltopdf: ${command}: ${r.error.message}`);
52
+ return 1;
53
+ }
54
+ return r.status === null ? 1 : r.status;
55
+ }
56
+
57
+ function update() {
58
+ const pkgDir = path.dirname(__dirname);
59
+ const before = readJson(path.join(pkgDir, "package.json")).version;
60
+ const found = project(pkgDir);
61
+ let command;
62
+ let args;
63
+ let cwd;
64
+ let after;
65
+ if (found) {
66
+ command = manager(found.dir);
67
+ const flag = {
68
+ devDependencies: { npm: "--save-dev", pnpm: "--save-dev", yarn: "--dev", bun: "--dev" },
69
+ optionalDependencies: { npm: "--save-optional", pnpm: "--save-optional", yarn: "--optional", bun: "--optional" },
70
+ }[found.section];
71
+ args = [command === "npm" ? "install" : "add", `${NAME}@latest`].concat(flag ? [flag[command]] : []);
72
+ cwd = found.dir;
73
+ after = path.join(found.dir, "node_modules", NAME, "package.json");
74
+ } else {
75
+ // installed with npm install --global, or by another package: then only npm's global folder is ours to update
76
+ const root = spawnSync("npm", ["root", "--global"], { encoding: "utf8", shell: windows });
77
+ const global = root.status === 0 && root.stdout.trim();
78
+ if (!global || path.resolve(global) !== path.resolve(path.dirname(pkgDir))) {
79
+ console.error(
80
+ `marqius-wkhtmltopdf: no package.json above ${pkgDir} names ${NAME}, so it came with another package. ` +
81
+ `Add it to your project, then update it there:\n\n npm install ${NAME}@latest`
82
+ );
83
+ return 1;
84
+ }
85
+ command = "npm";
86
+ args = ["install", "--global", `${NAME}@latest`];
87
+ cwd = process.cwd();
88
+ after = path.join(pkgDir, "package.json");
89
+ }
90
+ const shown = `${command} ${args.join(" ")}`;
91
+ console.log(`${NAME} ${before}: looking for a newer version (${shown}${found ? `, in ${cwd}` : ""})`);
92
+ const status = run(command, args, cwd);
93
+ if (status !== 0) {
94
+ console.error(`${NAME} was not updated: ${shown} failed.`);
95
+ return status;
96
+ }
97
+ const now = (readJson(after) || {}).version;
98
+ if (now === before) {
99
+ console.log(`${NAME} ${before} is the newest version.`);
100
+ } else {
101
+ console.log(`${NAME} is now ${now}.`);
102
+ }
103
+ return 0;
104
+ }
105
+
106
+ if (process.argv.slice(2).join(" ") === "update") {
107
+ process.exit(update());
108
+ }
6
109
 
7
110
  let program;
8
111
  try {
@@ -11,12 +114,12 @@ try {
11
114
  console.error(`marqius-wkhtmltopdf: ${e.message}`);
12
115
  process.exit(1);
13
116
  }
14
- const run = spawnSync(program, process.argv.slice(2), { stdio: "inherit" });
15
- if (run.error) {
16
- console.error(`marqius-wkhtmltopdf: ${run.error.message}`);
117
+ const runProgram = spawnSync(program, process.argv.slice(2), { stdio: "inherit" });
118
+ if (runProgram.error) {
119
+ console.error(`marqius-wkhtmltopdf: ${runProgram.error.message}`);
17
120
  process.exit(1);
18
121
  }
19
- if (run.signal) {
20
- process.kill(process.pid, run.signal);
122
+ if (runProgram.signal) {
123
+ process.kill(process.pid, runProgram.signal);
21
124
  }
22
- process.exit(run.status === null ? 1 : run.status);
125
+ process.exit(runProgram.status === null ? 1 : runProgram.status);
package/package.json CHANGED
@@ -1,13 +1,26 @@
1
1
  {
2
2
  "name": "marqius-wkhtmltopdf",
3
- "version": "0.12.13",
4
- "description": "marqius-wkhtmltopdf, the maintained drop-in replacement for wkhtmltopdf, for Node's wkhtmltopdf package (commercial, 30-day trial)",
3
+ "version": "0.12.14",
4
+ "description": "The maintained drop-in replacement for wkhtmltopdf, for Node's wkhtmltopdf and wkhtmltoimage packages. Prints Arabic, Hebrew, Hindi, Thai, Chinese, Japanese and Korean. Commercial, 30-day trial, free Community licence available.",
5
5
  "keywords": [
6
6
  "wkhtmltopdf",
7
7
  "wkhtmltoimage",
8
8
  "pdf",
9
9
  "html-to-pdf",
10
- "html2pdf"
10
+ "html2pdf",
11
+ "pdf-generation",
12
+ "html-to-image",
13
+ "invoice",
14
+ "rtl",
15
+ "arabic",
16
+ "hebrew",
17
+ "hindi",
18
+ "thai",
19
+ "chinese",
20
+ "japanese",
21
+ "korean",
22
+ "cjk",
23
+ "unicode"
11
24
  ],
12
25
  "homepage": "https://marqius.com/wkhtmltopdf/",
13
26
  "bugs": {
@@ -45,9 +58,9 @@
45
58
  "node": ">=14"
46
59
  },
47
60
  "optionalDependencies": {
48
- "marqius-wkhtmltopdf-darwin-arm64": "0.12.13",
49
- "marqius-wkhtmltopdf-linux-arm64": "0.12.13",
50
- "marqius-wkhtmltopdf-linux-x64": "0.12.13",
51
- "marqius-wkhtmltopdf-win32-x64": "0.12.13"
61
+ "marqius-wkhtmltopdf-darwin-arm64": "0.12.14",
62
+ "marqius-wkhtmltopdf-linux-arm64": "0.12.14",
63
+ "marqius-wkhtmltopdf-linux-x64": "0.12.14",
64
+ "marqius-wkhtmltopdf-win32-x64": "0.12.14"
52
65
  }
53
66
  }