marqius-wkhtmltopdf 0.0.0-stage → 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/LICENSE.md +27 -0
- package/README.md +247 -2
- package/bin/marqius-wkhtmltopdf.js +125 -0
- package/index.d.ts +8 -0
- package/index.js +91 -0
- package/index.mjs +5 -0
- package/package.json +64 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Licence
|
|
2
|
+
|
|
3
|
+
**The program.** marqius-wkhtmltopdf, which this package installs, is commercial
|
|
4
|
+
software from Simple AI LLC. Its use is governed by the marqius-wkhtmltopdf Licence Agreement:
|
|
5
|
+
https://marqius.com/wkhtmltopdf/licence-agreement/. It has a 30-day free trial counted from its first
|
|
6
|
+
run; after the trial, without a licence, each page it makes carries one line, "Prepared by Marqius,
|
|
7
|
+
Purchase Licence". Personal, teaching and open-source use is free with a Community licence. Plans and licences: https://marqius.com/licence/marqius-wkhtmltopdf
|
|
8
|
+
|
|
9
|
+
**This package's own files** (the JavaScript that finds the program for your platform and gives its path
|
|
10
|
+
to your library) are released under the MIT licence:
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 Simple AI LLC
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
15
|
+
associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
16
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
17
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
|
21
|
+
substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
24
|
+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
25
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
26
|
+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
27
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,248 @@
|
|
|
1
|
-
#
|
|
1
|
+
# wkhtmltopdf for Node.js: marqius-wkhtmltopdf for the wkhtmltopdf and wkhtmltoimage packages
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](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) |
|
|
49
|
+
|
|
50
|
+
## How do I install wkhtmltopdf with npm?
|
|
51
|
+
|
|
52
|
+
<!-- install -->
|
|
53
|
+
```bash
|
|
54
|
+
npm install marqius-wkhtmltopdf
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
npm installs the program for your platform from a matching optional dependency, as it does for esbuild. No install script downloads anything, so it works with `--ignore-scripts`, private registries and offline caches. It installs nothing under the name `wkhtmltopdf` on your system: your library gets the program's path from `require("marqius-wkhtmltopdf").path`, as below.
|
|
58
|
+
|
|
59
|
+
## How do I use it with the wkhtmltopdf package?
|
|
60
|
+
|
|
61
|
+
Give the package the path. Where your code has `const wkhtmltopdf = require("wkhtmltopdf");`:
|
|
62
|
+
|
|
63
|
+
<!-- example: wkhtmltopdf -->
|
|
64
|
+
```js
|
|
65
|
+
wkhtmltopdf.command = require("marqius-wkhtmltopdf").path;
|
|
66
|
+
wkhtmltopdf("<h1>Invoice 42</h1>", { output: "invoice.pdf" });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
On Linux and macOS the `wkhtmltopdf` package starts the program through a shell. If your project's folder has a space in its path, put the path in single quotes:
|
|
70
|
+
|
|
71
|
+
<!-- example: wkhtmltopdf quoted -->
|
|
72
|
+
```js
|
|
73
|
+
wkhtmltopdf.command = "'" + require("marqius-wkhtmltopdf").path + "'";
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## How do I make pictures with wkhtmltoimage?
|
|
77
|
+
|
|
78
|
+
Give it the path for pictures, `.imagePath`. Where your code has `const wkhtmltoimage = require("wkhtmltoimage");`:
|
|
79
|
+
|
|
80
|
+
<!-- example: wkhtmltoimage -->
|
|
81
|
+
```js
|
|
82
|
+
wkhtmltoimage.setCommand(require("marqius-wkhtmltopdf").imagePath);
|
|
83
|
+
wkhtmltoimage.generate("<h1>Invoice 42</h1>", { output: "invoice.jpg" });
|
|
84
|
+
```
|
|
85
|
+
|
|
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?
|
|
99
|
+
|
|
100
|
+
Yes. The package comes with its own types, and `marqius.path` is the same path:
|
|
101
|
+
|
|
102
|
+
<!-- example: import -->
|
|
103
|
+
```js
|
|
104
|
+
import marqius from "marqius-wkhtmltopdf";
|
|
105
|
+
```
|
|
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
|
+
|
|
177
|
+
## Why do I get "wkhtmltopdf: command not found"?
|
|
178
|
+
|
|
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.
|
|
180
|
+
|
|
181
|
+
## Why does wkhtmltopdf fail with "libssl.so.1.1: cannot open shared object file"?
|
|
182
|
+
|
|
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.
|
|
184
|
+
|
|
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?
|
|
198
|
+
|
|
199
|
+
It runs on:
|
|
200
|
+
|
|
201
|
+
- Linux on x64 and arm64, with glibc or musl, so Debian 13, Ubuntu 24.04 and Alpine too;
|
|
202
|
+
- Macs with Apple silicon;
|
|
203
|
+
- Windows on x64.
|
|
204
|
+
|
|
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.
|
|
206
|
+
|
|
207
|
+
## Is marqius-wkhtmltopdf free?
|
|
208
|
+
|
|
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.
|
|
210
|
+
|
|
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).
|
|
212
|
+
|
|
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/)
|
|
214
|
+
|
|
215
|
+
## How do I add my licence key?
|
|
216
|
+
|
|
217
|
+
Set the `MARQIUS_LICENCE` environment variable to your licence; that is the way for containers and CI. Or save it as `licence.txt` and run `npx marqius-wkhtmltopdf licence add licence.txt`. `npx marqius-wkhtmltopdf licence` shows the trial's days left, or the licence in force.
|
|
218
|
+
|
|
219
|
+
## Does the wkhtmltopdf package pass its own tests?
|
|
220
|
+
|
|
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).
|
|
222
|
+
|
|
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.
|
|
224
|
+
|
|
225
|
+
## How do I update it?
|
|
226
|
+
|
|
227
|
+
Run this in your project. It installs the newest version with your project's package manager: npm, pnpm, yarn or bun:
|
|
228
|
+
|
|
229
|
+
<!-- update -->
|
|
230
|
+
```bash
|
|
231
|
+
npx marqius-wkhtmltopdf update
|
|
232
|
+
```
|
|
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
|
+
|
|
236
|
+
## What else does the program do?
|
|
237
|
+
|
|
238
|
+
`npx marqius-wkhtmltopdf` runs it under its own name:
|
|
239
|
+
|
|
240
|
+
- `npx marqius-wkhtmltopdf help node` shows each library's setting;
|
|
241
|
+
- `npx marqius-wkhtmltopdf compare old.pdf new.pdf` lists every difference between a PDF made by wkhtmltopdf and one made by marqius-wkhtmltopdf;
|
|
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`.
|
|
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
|
+
|
|
248
|
+
This package's own JavaScript files are under the MIT licence: [LICENSE.md](LICENSE.md).
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// marqius-wkhtmltopdf under its own name (npx marqius-wkhtmltopdf): help, licence, compare,
|
|
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.
|
|
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
|
+
}
|
|
109
|
+
|
|
110
|
+
let program;
|
|
111
|
+
try {
|
|
112
|
+
program = require("..").program;
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.error(`marqius-wkhtmltopdf: ${e.message}`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
const runProgram = spawnSync(program, process.argv.slice(2), { stdio: "inherit" });
|
|
118
|
+
if (runProgram.error) {
|
|
119
|
+
console.error(`marqius-wkhtmltopdf: ${runProgram.error.message}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
if (runProgram.signal) {
|
|
123
|
+
process.kill(process.pid, runProgram.signal);
|
|
124
|
+
}
|
|
125
|
+
process.exit(runProgram.status === null ? 1 : runProgram.status);
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The release of marqius-wkhtmltopdf this package carries, such as "0.12.10". */
|
|
2
|
+
export declare const version: string;
|
|
3
|
+
/** The installed program's path, as wkhtmltopdf: give it where a library asks for wkhtmltopdf. */
|
|
4
|
+
export declare const path: string;
|
|
5
|
+
/** Its path as wkhtmltoimage, for pictures. */
|
|
6
|
+
export declare const imagePath: string;
|
|
7
|
+
/** The program under its own name, marqius-wkhtmltopdf: help, licence, compare and install. */
|
|
8
|
+
export declare const program: string;
|
package/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// marqius-wkhtmltopdf for Node: require("marqius-wkhtmltopdf").path is the installed program's
|
|
3
|
+
// path, to give the wkhtmltopdf package (or another library that runs wkhtmltopdf). npm installs
|
|
4
|
+
// the program for this machine with this package, from the optional dependency that matches it;
|
|
5
|
+
// nothing is downloaded at install.
|
|
6
|
+
// marqius-wkhtmltopdf is commercial software from Simple AI LLC, with a 30-day free trial:
|
|
7
|
+
// https://marqius.com/licence/marqius-wkhtmltopdf
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const { version } = require("./package.json");
|
|
12
|
+
|
|
13
|
+
const BUILDS = {
|
|
14
|
+
"linux x64": "marqius-wkhtmltopdf-linux-x64",
|
|
15
|
+
"linux arm64": "marqius-wkhtmltopdf-linux-arm64",
|
|
16
|
+
"darwin arm64": "marqius-wkhtmltopdf-darwin-arm64",
|
|
17
|
+
"win32 x64": "marqius-wkhtmltopdf-win32-x64",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const windows = process.platform === "win32";
|
|
21
|
+
|
|
22
|
+
// the folder holding the program, in the package npm installed for this platform
|
|
23
|
+
function folder() {
|
|
24
|
+
const here = `${process.platform} ${process.arch}`;
|
|
25
|
+
const pkg = BUILDS[here];
|
|
26
|
+
if (!pkg) {
|
|
27
|
+
let why = `marqius-wkhtmltopdf has no build for ${here}: it runs on Linux (x64 and arm64), Apple silicon Macs and Windows (x64).`;
|
|
28
|
+
if (here === "darwin x64") {
|
|
29
|
+
why += " On a Mac with Apple silicon, use Node for Apple silicon rather than Node for Intel; for Intel Macs, write to hello@marqius.com.";
|
|
30
|
+
}
|
|
31
|
+
throw new Error(why);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return path.join(path.dirname(require.resolve(`${pkg}/package.json`)), "bin");
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`marqius-wkhtmltopdf cannot find ${pkg}, which holds the program for ${here}. npm installs it with ` +
|
|
38
|
+
`marqius-wkhtmltopdf unless optional dependencies are left out (--omit=optional, --no-optional) or the ` +
|
|
39
|
+
`lockfile was made on another platform without it. Run "npm install marqius-wkhtmltopdf" again on this machine.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// On Windows, the program answers to wkhtmltopdf.exe and wkhtmltoimage.exe by their file names:
|
|
45
|
+
// hard links beside it (copies where links cannot be made). Elsewhere a few lines of sh in the
|
|
46
|
+
// package start it under each name.
|
|
47
|
+
function named(dir, name) {
|
|
48
|
+
if (!windows) {
|
|
49
|
+
return path.join(dir, name);
|
|
50
|
+
}
|
|
51
|
+
const program = path.join(dir, "marqius-wkhtmltopdf.exe");
|
|
52
|
+
const size = fs.statSync(program).size;
|
|
53
|
+
for (const place of [dir, path.join(os.tmpdir(), `marqius-wkhtmltopdf-${version}`)]) {
|
|
54
|
+
const to = path.join(place, `${name}.exe`);
|
|
55
|
+
try {
|
|
56
|
+
if (fs.statSync(to).size === size) {
|
|
57
|
+
return to;
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
// not made yet
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
fs.mkdirSync(place, { recursive: true });
|
|
64
|
+
try {
|
|
65
|
+
fs.unlinkSync(to);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
// nothing to replace
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
fs.linkSync(program, to);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
fs.copyFileSync(program, to);
|
|
73
|
+
}
|
|
74
|
+
return to;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
// this folder cannot be written: try the next
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`marqius-wkhtmltopdf cannot be given the name ${name}.exe: neither ${dir} nor ${os.tmpdir()} can be written`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const dir = folder();
|
|
83
|
+
|
|
84
|
+
/** The release of marqius-wkhtmltopdf this package carries, such as "0.12.10". */
|
|
85
|
+
exports.version = version;
|
|
86
|
+
/** The installed program's path, as wkhtmltopdf: give it where a library asks for wkhtmltopdf. */
|
|
87
|
+
exports.path = named(dir, "wkhtmltopdf");
|
|
88
|
+
/** Its path as wkhtmltoimage, for pictures. */
|
|
89
|
+
exports.imagePath = named(dir, "wkhtmltoimage");
|
|
90
|
+
/** The program under its own name, marqius-wkhtmltopdf: help, licence, compare and install. */
|
|
91
|
+
exports.program = path.join(dir, windows ? "marqius-wkhtmltopdf.exe" : "marqius-wkhtmltopdf");
|
package/index.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marqius-wkhtmltopdf",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
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
|
+
"keywords": [
|
|
6
|
+
"wkhtmltopdf",
|
|
7
|
+
"wkhtmltoimage",
|
|
8
|
+
"pdf",
|
|
9
|
+
"html-to-pdf",
|
|
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"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://marqius.com/wkhtmltopdf/",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/marqiushq/marqius-wkhtmltopdf-node/issues",
|
|
28
|
+
"email": "hello@marqius.com"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/marqiushq/marqius-wkhtmltopdf-node.git",
|
|
33
|
+
"directory": "marqius-wkhtmltopdf"
|
|
34
|
+
},
|
|
35
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
36
|
+
"author": "Simple AI LLC <hello@marqius.com> (https://marqius.com)",
|
|
37
|
+
"main": "index.js",
|
|
38
|
+
"types": "index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./index.d.ts",
|
|
42
|
+
"import": "./index.mjs",
|
|
43
|
+
"require": "./index.js"
|
|
44
|
+
},
|
|
45
|
+
"./package.json": "./package.json"
|
|
46
|
+
},
|
|
47
|
+
"bin": {
|
|
48
|
+
"marqius-wkhtmltopdf": "bin/marqius-wkhtmltopdf.js"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"index.js",
|
|
52
|
+
"index.mjs",
|
|
53
|
+
"index.d.ts",
|
|
54
|
+
"bin/marqius-wkhtmltopdf.js",
|
|
55
|
+
"LICENSE.md"
|
|
56
|
+
],
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=14"
|
|
59
|
+
},
|
|
60
|
+
"optionalDependencies": {
|
|
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"
|
|
65
|
+
}
|
|
66
|
+
}
|