pdf-fox 1.0.0 → 1.1.0
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 +21 -0
- package/README.md +92 -0
- package/dist/cli.js +38 -3
- package/dist/cli.js.map +1 -1
- package/dist/converter.d.ts.map +1 -1
- package/dist/converter.js +84 -13
- package/dist/converter.js.map +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sa2taka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# pdf-fox
|
|
2
|
+
|
|
3
|
+
PDF to PNG converter for Node.js, powered by [PDF.js](https://mozilla.github.io/pdf.js/) and [@napi-rs/canvas](https://github.com/Brooooooklyn/canvas).
|
|
4
|
+
|
|
5
|
+
[日本語](./README_ja.md)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install pdf-fox
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## CLI
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Convert all pages
|
|
17
|
+
npx pdf-fox input.pdf
|
|
18
|
+
|
|
19
|
+
# Specify output directory
|
|
20
|
+
npx pdf-fox input.pdf -o output/
|
|
21
|
+
|
|
22
|
+
# Convert a specific page
|
|
23
|
+
npx pdf-fox input.pdf -p 2
|
|
24
|
+
|
|
25
|
+
# Set resolution (default: 200 DPI)
|
|
26
|
+
npx pdf-fox input.pdf --dpi 300
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Options:
|
|
31
|
+
-o, --output <path> Output directory or file path
|
|
32
|
+
-p, --page <number> Page number to convert (default: all pages)
|
|
33
|
+
-r, --dpi <number> Resolution in DPI (default: 200)
|
|
34
|
+
-b, --background <color> Background color (default: white)
|
|
35
|
+
-f, --font <name=path> Substitute font for a non-embedded font (repeatable)
|
|
36
|
+
--no-system-fonts Disable automatic CJK system-font fallback
|
|
37
|
+
-h, --help Show help
|
|
38
|
+
-V, --version Show version
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Non-embedded fonts
|
|
42
|
+
|
|
43
|
+
If a PDF references a font without embedding it, those glyphs would render as
|
|
44
|
+
blank boxes. By default pdf-fox points the generic `serif`/`sans-serif`
|
|
45
|
+
families at an available CJK system font (Hiragino, Yu, MS, Noto, …), so such
|
|
46
|
+
text renders out of the box — just like Firefox falling back to system fonts.
|
|
47
|
+
Disable this with `--no-system-fonts` for output that doesn't depend on
|
|
48
|
+
installed fonts.
|
|
49
|
+
|
|
50
|
+
To use a specific font (e.g. when the system has none, or to match the
|
|
51
|
+
original exactly), supply a local font file under the name the PDF uses:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx pdf-fox input.pdf -f "MSMincho=~/Library/Fonts/msmincho.ttc"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The name (`MSMincho`) is the PDF's font name without its subset prefix (the
|
|
58
|
+
part before `+`). You can inspect font names with `pdffonts input.pdf`.
|
|
59
|
+
|
|
60
|
+
## Library
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { convertPdfToPng, convertPdfPageToPng } from "pdf-fox";
|
|
64
|
+
import { readFileSync } from "fs";
|
|
65
|
+
|
|
66
|
+
const pdf = readFileSync("input.pdf");
|
|
67
|
+
|
|
68
|
+
// All pages
|
|
69
|
+
const pages = await convertPdfToPng(pdf);
|
|
70
|
+
// => [{ pageNumber: 1, data: Buffer, width: number, height: number }, ...]
|
|
71
|
+
|
|
72
|
+
// Specific page
|
|
73
|
+
const page = await convertPdfPageToPng(pdf, 1, { scale: 2.0 });
|
|
74
|
+
|
|
75
|
+
// Substitute a non-embedded font
|
|
76
|
+
const rendered = await convertPdfToPng(pdf, {
|
|
77
|
+
fonts: { MSMincho: "/path/to/msmincho.ttc" },
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Options
|
|
82
|
+
|
|
83
|
+
| Option | Type | Default | Description |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| `scale` | `number` | `1.5` | Rendering scale (1.0 = 72 DPI) |
|
|
86
|
+
| `background` | `string` | `"white"` | Background color (any CSS color string) |
|
|
87
|
+
| `fonts` | `Record<string, string>` | `{}` | Substitute fonts for non-embedded fonts, mapping the PDF's font name to a local font file path |
|
|
88
|
+
| `systemFontFallback` | `boolean` | `true` | Point `serif`/`sans-serif` at an available CJK system font so non-embedded CJK text renders. Disable for font-independent output |
|
|
89
|
+
|
|
90
|
+
## Requirements
|
|
91
|
+
|
|
92
|
+
- Node.js 18+
|
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { parseArgs } from "util";
|
|
3
3
|
import { readFileSync, writeFileSync, mkdirSync, existsSync, statSync } from "fs";
|
|
4
4
|
import { resolve, basename, extname, dirname, join } from "path";
|
|
5
|
+
import { homedir } from "os";
|
|
5
6
|
import { createRequire } from "module";
|
|
6
7
|
import { convertPdfToPng, convertPdfPageToPng } from "./index.js";
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
@@ -20,6 +21,9 @@ Options:
|
|
|
20
21
|
-p, --page <number> 変換するページ番号(省略時は全ページ)
|
|
21
22
|
-r, --dpi <number> 解像度 DPI(デフォルト: ${DEFAULT_DPI})
|
|
22
23
|
-b, --background <color> 背景色(デフォルト: white)
|
|
24
|
+
-f, --font <name=path> PDF が埋め込んでいないフォントの代替を指定
|
|
25
|
+
(複数指定可。name は PDF 内のフォント名)
|
|
26
|
+
--no-system-fonts CJK システムフォントへの自動フォールバックを無効化
|
|
23
27
|
-h, --help ヘルプを表示
|
|
24
28
|
-V, --version バージョンを表示
|
|
25
29
|
|
|
@@ -29,6 +33,7 @@ Examples:
|
|
|
29
33
|
pdf-fox doc.pdf -p 2 2ページ目のみ変換
|
|
30
34
|
pdf-fox doc.pdf -p 1 -o cover.png 1ページ目を cover.png として保存
|
|
31
35
|
pdf-fox doc.pdf --dpi 300 300 DPI で変換
|
|
36
|
+
pdf-fox doc.pdf -f MSMincho=~/Library/Fonts/msmincho.ttc
|
|
32
37
|
`;
|
|
33
38
|
function parseCliArgs() {
|
|
34
39
|
const { values, positionals } = parseArgs({
|
|
@@ -37,6 +42,8 @@ function parseCliArgs() {
|
|
|
37
42
|
page: { type: "string", short: "p" },
|
|
38
43
|
dpi: { type: "string", short: "r" },
|
|
39
44
|
background: { type: "string", short: "b" },
|
|
45
|
+
font: { type: "string", short: "f", multiple: true },
|
|
46
|
+
"no-system-fonts": { type: "boolean" },
|
|
40
47
|
help: { type: "boolean", short: "h" },
|
|
41
48
|
version: { type: "boolean", short: "V" },
|
|
42
49
|
},
|
|
@@ -69,8 +76,31 @@ function parseCliArgs() {
|
|
|
69
76
|
page,
|
|
70
77
|
dpi,
|
|
71
78
|
background: values.background ?? "white",
|
|
79
|
+
fonts: parseFontMappings(values.font),
|
|
80
|
+
systemFontFallback: !values["no-system-fonts"],
|
|
72
81
|
};
|
|
73
82
|
}
|
|
83
|
+
// Parses repeated `--font name=path` values into a name → path map.
|
|
84
|
+
function parseFontMappings(values) {
|
|
85
|
+
const fonts = {};
|
|
86
|
+
for (const value of values ?? []) {
|
|
87
|
+
const separator = value.indexOf("=");
|
|
88
|
+
if (separator <= 0) {
|
|
89
|
+
exitWithError(`--font は "name=path" 形式で指定してください: ${value}`);
|
|
90
|
+
}
|
|
91
|
+
const name = value.slice(0, separator);
|
|
92
|
+
const path = value.slice(separator + 1);
|
|
93
|
+
fonts[name] = resolveHome(path);
|
|
94
|
+
}
|
|
95
|
+
return fonts;
|
|
96
|
+
}
|
|
97
|
+
// Expands a leading "~" to the user's home directory.
|
|
98
|
+
function resolveHome(path) {
|
|
99
|
+
if (path === "~" || path.startsWith("~/")) {
|
|
100
|
+
return join(homedir(), path.slice(1));
|
|
101
|
+
}
|
|
102
|
+
return path;
|
|
103
|
+
}
|
|
74
104
|
function resolveOutputSpec(inputPath, outputOption) {
|
|
75
105
|
const stem = basename(inputPath, extname(inputPath));
|
|
76
106
|
if (!outputOption) {
|
|
@@ -98,7 +128,7 @@ function exitWithError(message) {
|
|
|
98
128
|
process.exit(1);
|
|
99
129
|
}
|
|
100
130
|
async function run() {
|
|
101
|
-
const { inputPath, outputOption, page, dpi, background } = parseCliArgs();
|
|
131
|
+
const { inputPath, outputOption, page, dpi, background, fonts, systemFontFallback } = parseCliArgs();
|
|
102
132
|
const scale = dpi / PDF_BASE_DPI;
|
|
103
133
|
let pdfBuffer;
|
|
104
134
|
try {
|
|
@@ -111,7 +141,12 @@ async function run() {
|
|
|
111
141
|
if (page !== undefined) {
|
|
112
142
|
let result;
|
|
113
143
|
try {
|
|
114
|
-
result = await convertPdfPageToPng(pdfBuffer, page, {
|
|
144
|
+
result = await convertPdfPageToPng(pdfBuffer, page, {
|
|
145
|
+
scale,
|
|
146
|
+
background,
|
|
147
|
+
fonts,
|
|
148
|
+
systemFontFallback,
|
|
149
|
+
});
|
|
115
150
|
}
|
|
116
151
|
catch (err) {
|
|
117
152
|
exitWithError(err instanceof Error ? err.message : String(err));
|
|
@@ -121,7 +156,7 @@ async function run() {
|
|
|
121
156
|
}
|
|
122
157
|
let pages;
|
|
123
158
|
try {
|
|
124
|
-
pages = await convertPdfToPng(pdfBuffer, { scale, background });
|
|
159
|
+
pages = await convertPdfToPng(pdfBuffer, { scale, background, fonts, systemFontFallback });
|
|
125
160
|
}
|
|
126
161
|
catch (err) {
|
|
127
162
|
exitWithError(err instanceof Error ? err.message : String(err));
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGlE,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;A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+
{"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA2G1D,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,MAAM,GAAG,UAAU,EAC1B,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,OAAO,CAAC,CAIlB;AAED,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,GAAG,UAAU,EAC1B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,OAAO,EAAE,CAAC,CAYpB"}
|
package/dist/converter.js
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
|
-
import { createCanvas } from "@napi-rs/canvas";
|
|
1
|
+
import { createCanvas, GlobalFonts } from "@napi-rs/canvas";
|
|
2
2
|
import { createRequire } from "module";
|
|
3
3
|
import { getDocument, GlobalWorkerOptions } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
4
4
|
const DEFAULT_SCALE = 1.5;
|
|
5
5
|
const DEFAULT_BACKGROUND = "white";
|
|
6
|
+
// CJK system fonts to alias to the generic families, in preference order across
|
|
7
|
+
// macOS, Windows and common Linux installs. The first available one wins.
|
|
8
|
+
const CJK_SERIF_FONTS = [
|
|
9
|
+
"Hiragino Mincho ProN",
|
|
10
|
+
"YuMincho",
|
|
11
|
+
"Yu Mincho",
|
|
12
|
+
"MS Mincho",
|
|
13
|
+
"Noto Serif CJK JP",
|
|
14
|
+
"Noto Serif JP",
|
|
15
|
+
"Source Han Serif JP",
|
|
16
|
+
"IPAexMincho",
|
|
17
|
+
];
|
|
18
|
+
const CJK_SANS_FONTS = [
|
|
19
|
+
"Hiragino Sans",
|
|
20
|
+
"Hiragino Kaku Gothic ProN",
|
|
21
|
+
"YuGothic",
|
|
22
|
+
"Yu Gothic",
|
|
23
|
+
"Meiryo",
|
|
24
|
+
"MS Gothic",
|
|
25
|
+
"Noto Sans CJK JP",
|
|
26
|
+
"Noto Sans JP",
|
|
27
|
+
"Source Han Sans JP",
|
|
28
|
+
"IPAexGothic",
|
|
29
|
+
];
|
|
6
30
|
// Use createRequire so Node.js resolves paths from node_modules,
|
|
7
31
|
// not relative to this source file.
|
|
8
32
|
const require = createRequire(import.meta.url);
|
|
@@ -10,15 +34,24 @@ const workerPath = require.resolve("pdfjs-dist/legacy/build/pdf.worker.min.mjs")
|
|
|
10
34
|
GlobalWorkerOptions.workerSrc = `file://${workerPath}`;
|
|
11
35
|
// pdfjs-dist's NodeBinaryDataFactory uses fs.readFile(url) which accepts plain
|
|
12
36
|
// file paths but not "file://" string URLs. Passing the directory path directly
|
|
13
|
-
// (with trailing slash) lets fs.readFile resolve
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
37
|
+
// (with trailing slash) lets fs.readFile resolve bundled assets correctly.
|
|
38
|
+
const STANDARD_FONT_DATA_URL = resolveBundledDir("pdfjs-dist/standard_fonts/FoxitSerif.pfb", "FoxitSerif.pfb");
|
|
39
|
+
// CMaps map character codes to glyphs for CID-keyed fonts that reference
|
|
40
|
+
// predefined Adobe CMaps (e.g. UniJIS-UTF16-H) instead of embedding their own.
|
|
41
|
+
// Without these, non-embedded CJK fonts fail to render.
|
|
42
|
+
const CMAP_URL = resolveBundledDir("pdfjs-dist/cmaps/UniJIS-UTF16-H.bcmap", "UniJIS-UTF16-H.bcmap");
|
|
43
|
+
function loadPdfDocument(pdfData) {
|
|
19
44
|
// PDF.js transfers the ArrayBuffer to the worker thread (detaching it), so we
|
|
20
45
|
// must pass a fresh copy per getDocument call to allow parallel rendering.
|
|
21
|
-
|
|
46
|
+
return getDocument({
|
|
47
|
+
data: new Uint8Array(pdfData),
|
|
48
|
+
standardFontDataUrl: STANDARD_FONT_DATA_URL,
|
|
49
|
+
cMapUrl: CMAP_URL,
|
|
50
|
+
cMapPacked: true,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function renderPageToPng(pdfData, pageNumber, options) {
|
|
54
|
+
const loadingTask = loadPdfDocument(pdfData);
|
|
22
55
|
const pdfDocument = await loadingTask.promise;
|
|
23
56
|
try {
|
|
24
57
|
const page = await pdfDocument.getPage(pageNumber);
|
|
@@ -48,18 +81,19 @@ async function renderPageToPng(pdfData, pageNumber, options) {
|
|
|
48
81
|
}
|
|
49
82
|
}
|
|
50
83
|
export async function convertPdfPageToPng(input, pageNumber, options) {
|
|
51
|
-
|
|
84
|
+
prepareFonts(options);
|
|
52
85
|
const pdfData = toUint8Array(input);
|
|
53
|
-
return renderPageToPng(pdfData, pageNumber,
|
|
86
|
+
return renderPageToPng(pdfData, pageNumber, resolveOptions(options));
|
|
54
87
|
}
|
|
55
88
|
export async function convertPdfToPng(input, options) {
|
|
56
|
-
|
|
89
|
+
prepareFonts(options);
|
|
57
90
|
const pdfData = toUint8Array(input);
|
|
91
|
+
const renderOptions = resolveOptions(options);
|
|
58
92
|
const pageCount = await getPageCount(pdfData);
|
|
59
|
-
return Promise.all(Array.from({ length: pageCount }, (_, i) => renderPageToPng(pdfData, i + 1,
|
|
93
|
+
return Promise.all(Array.from({ length: pageCount }, (_, i) => renderPageToPng(pdfData, i + 1, renderOptions)));
|
|
60
94
|
}
|
|
61
95
|
async function getPageCount(pdfData) {
|
|
62
|
-
const loadingTask =
|
|
96
|
+
const loadingTask = loadPdfDocument(pdfData);
|
|
63
97
|
const pdfDocument = await loadingTask.promise;
|
|
64
98
|
const count = pdfDocument.numPages;
|
|
65
99
|
await pdfDocument.cleanup();
|
|
@@ -72,7 +106,44 @@ function resolveOptions(options) {
|
|
|
72
106
|
background: options?.background ?? DEFAULT_BACKGROUND,
|
|
73
107
|
};
|
|
74
108
|
}
|
|
109
|
+
// Sets up font substitution before rendering. Must run before any rendering:
|
|
110
|
+
// @napi-rs/canvas caches font lookups per process, so fonts registered after
|
|
111
|
+
// their first use won't take effect.
|
|
112
|
+
function prepareFonts(options) {
|
|
113
|
+
if (options?.systemFontFallback !== false) {
|
|
114
|
+
applySystemFontFallback();
|
|
115
|
+
}
|
|
116
|
+
registerFonts(options?.fonts);
|
|
117
|
+
}
|
|
118
|
+
// Aliases an available CJK system font to each generic family, so PDF.js's
|
|
119
|
+
// `"<fontName>", serif` / `sans-serif` fallback resolves to a font that can
|
|
120
|
+
// actually draw the glyphs of non-embedded CJK fonts.
|
|
121
|
+
function applySystemFontFallback() {
|
|
122
|
+
aliasFirstAvailable(CJK_SERIF_FONTS, "serif");
|
|
123
|
+
aliasFirstAvailable(CJK_SANS_FONTS, "sans-serif");
|
|
124
|
+
}
|
|
125
|
+
function aliasFirstAvailable(candidates, generic) {
|
|
126
|
+
const available = candidates.find((name) => GlobalFonts.has(name));
|
|
127
|
+
if (available) {
|
|
128
|
+
GlobalFonts.setAlias(available, generic);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Registers substitute fonts under the names PDF.js requests for specific
|
|
132
|
+
// non-embedded fonts.
|
|
133
|
+
function registerFonts(fonts) {
|
|
134
|
+
if (!fonts)
|
|
135
|
+
return;
|
|
136
|
+
for (const [name, path] of Object.entries(fonts)) {
|
|
137
|
+
if (GlobalFonts.registerFromPath(path, name) === null) {
|
|
138
|
+
throw new Error(`Failed to register font "${name}" from: ${path}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
75
142
|
function toUint8Array(input) {
|
|
76
143
|
return new Uint8Array(input);
|
|
77
144
|
}
|
|
145
|
+
// Resolves the directory of a bundled pdfjs-dist asset as a trailing-slash path.
|
|
146
|
+
function resolveBundledDir(modulePath, fileName) {
|
|
147
|
+
return require.resolve(modulePath).replace(fileName, "");
|
|
148
|
+
}
|
|
78
149
|
//# sourceMappingURL=converter.js.map
|
package/dist/converter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAAA,OAAO,EA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S,YAAY,CAAC,KAA0B;IAC9C,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,iFAAiF;AACjF,SAAS,iBAAiB,CAAC,UAAkB,EAAE,QAAgB;IAC7D,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC3D,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -9,6 +9,27 @@ export interface ConvertOptions {
|
|
|
9
9
|
* @default "white"
|
|
10
10
|
*/
|
|
11
11
|
background?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Substitute fonts for fonts that the PDF references but does not embed.
|
|
14
|
+
* Maps a font name as referenced in the PDF (e.g. "MSMincho") to a local
|
|
15
|
+
* font file path.
|
|
16
|
+
*
|
|
17
|
+
* Without a substitute, glyphs of non-embedded fonts fall back to a generic
|
|
18
|
+
* family that may lack the required glyphs (rendered as blank boxes).
|
|
19
|
+
*
|
|
20
|
+
* The key must match the name PDF.js requests, which is the PDF's BaseFont
|
|
21
|
+
* name without its subset prefix (the part before "+").
|
|
22
|
+
*/
|
|
23
|
+
fonts?: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Point the generic "serif"/"sans-serif" families at an available CJK system
|
|
26
|
+
* font so non-embedded CJK fonts render instead of showing blank boxes —
|
|
27
|
+
* mirroring how Firefox falls back to system fonts.
|
|
28
|
+
*
|
|
29
|
+
* Disable for reproducible output that doesn't depend on installed fonts.
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
systemFontFallback?: boolean;
|
|
12
33
|
}
|
|
13
34
|
export interface PngPage {
|
|
14
35
|
/** 1-indexed page number */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE/B;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,OAAO;IACtB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-fox",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "PDF to PNG converter using PDF.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"pdf-fox": "
|
|
9
|
+
"pdf-fox": "dist/cli.js"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
@@ -29,8 +29,16 @@
|
|
|
29
29
|
"converter",
|
|
30
30
|
"pdfjs"
|
|
31
31
|
],
|
|
32
|
-
"author": "",
|
|
33
|
-
"license": "
|
|
32
|
+
"author": "sa2taka <sa2taka@gmail.com>",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/sa2taka/pdf-fox.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/sa2taka/pdf-fox/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/sa2taka/pdf-fox#readme",
|
|
34
42
|
"dependencies": {
|
|
35
43
|
"@napi-rs/canvas": "^1.0.0",
|
|
36
44
|
"pdfjs-dist": "^6.0.227"
|