@react-pdf-kit/viewer 2.8.0 → 2.9.0-beta.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/README.md
CHANGED
|
@@ -182,6 +182,16 @@ The PDF viewer will automatically adjust to fit its container's dimensions. You
|
|
|
182
182
|
|
|
183
183
|
You may also check out our [Starter Toolkit](#pushpin-starter-toolkit) for examples to get you started.
|
|
184
184
|
|
|
185
|
+
### Standard Font Assets
|
|
186
|
+
|
|
187
|
+
For PDFs that use standard fonts without embedding them, configure PDF.js with the location of its standard-font assets. The URL must include a trailing slash:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
<RPConfig standardFontDataUrl="/pdfjs/standard_fonts/">
|
|
191
|
+
{/* viewer components */}
|
|
192
|
+
</RPConfig>
|
|
193
|
+
```
|
|
194
|
+
|
|
185
195
|
### 4. Customize with Hooks and Props
|
|
186
196
|
|
|
187
197
|
To enhance React PDF Kit further, we offer built-in hooks and props that let you fine-tune functionality, adjust appearance, and integrate custom behaviors into your application.
|
|
@@ -6,13 +6,14 @@ import { useLoadWorker as r } from "../utils/hooks/useLoadWorker.js";
|
|
|
6
6
|
import { jsx as i } from "react/jsx-runtime";
|
|
7
7
|
//#region lib/components/RPConfig.tsx
|
|
8
8
|
var a = (a) => {
|
|
9
|
-
let { children: o, customVariables: s, customDarkVariables: c, workerUrl: l, wasmUrl: u,
|
|
9
|
+
let { children: o, customVariables: s, customDarkVariables: c, workerUrl: l, wasmUrl: u, standardFontDataUrl: d, licenseKey: f, ...p } = a, { workerUrlAdded: m } = r(l);
|
|
10
10
|
return /* @__PURE__ */ i(t, {
|
|
11
|
-
licenseKey:
|
|
11
|
+
licenseKey: f,
|
|
12
12
|
children: /* @__PURE__ */ i(e, {
|
|
13
|
-
workerUrlAdded:
|
|
13
|
+
workerUrlAdded: m,
|
|
14
14
|
wasmUrl: u,
|
|
15
|
-
|
|
15
|
+
standardFontDataUrl: d,
|
|
16
|
+
...p,
|
|
16
17
|
children: /* @__PURE__ */ i(n, {
|
|
17
18
|
customDarkVariables: c,
|
|
18
19
|
customVariables: s,
|
|
@@ -3,7 +3,8 @@ import { jsx as n } from "react/jsx-runtime";
|
|
|
3
3
|
//#region lib/contexts/ConfigContext.tsx
|
|
4
4
|
var r = e({
|
|
5
5
|
workerUrlAdded: !1,
|
|
6
|
-
wasmUrl: void 0
|
|
6
|
+
wasmUrl: void 0,
|
|
7
|
+
standardFontDataUrl: void 0
|
|
7
8
|
}), i = () => t(r), a = (e) => {
|
|
8
9
|
let { children: t, ...i } = e;
|
|
9
10
|
return /* @__PURE__ */ n(r.Provider, {
|
|
@@ -3,7 +3,7 @@ import { LicenseType as t } from "../types.js";
|
|
|
3
3
|
import { appConsole as n } from "../appConsole.js";
|
|
4
4
|
import { useCallback as r, useEffect as i, useState as a } from "react";
|
|
5
5
|
//#region lib/utils/hooks/useLicense.ts
|
|
6
|
-
var o = /* @__PURE__ */ new Date("2026-08-
|
|
6
|
+
var o = /* @__PURE__ */ new Date("2026-08-10T06:12:32.238Z"), s = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx\ngr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b\nHLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y\nBm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W\nvXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD\nvzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR\nkwIDAQAB\n-----END PUBLIC KEY-----", c = "Please visit https://app.react-pdf-kit.dev to generate a new license key.", l = {
|
|
7
7
|
invalidLicense: `You are currently using without a valid license. ${c}`,
|
|
8
8
|
mismatchedDomain: `Your license key is not valid for the current domain / IP. ${c}`,
|
|
9
9
|
expired: `Your license key has expired. ${c}`,
|
|
@@ -24,40 +24,41 @@ function _(e) {
|
|
|
24
24
|
return t.cause = e, t;
|
|
25
25
|
}
|
|
26
26
|
var v = (a, o, c = {}) => {
|
|
27
|
-
let [p, v] = d(), { workerUrlAdded: y, wasmUrl: b } = n(), [
|
|
27
|
+
let [p, v] = d(), { workerUrlAdded: y, wasmUrl: b, standardFontDataUrl: x } = n(), [S, C] = d(/* @__PURE__ */ new Map()), w = u(), [T, E] = d(0), [D, O] = d(!1), [k, A] = d(), { password: j, passwordError: M, setPasswordError: N, passwordRequired: P, setPasswordRequired: F } = i(), { onLoadError: I, onLoaded: L, onLoadProgress: R, disableAutoFetch: z, disableStream: B, rangeChunkSize: V, withCredentials: H, httpHeaders: U } = c;
|
|
28
28
|
return l(() => {
|
|
29
|
-
|
|
30
|
-
}, [
|
|
29
|
+
R && R(T);
|
|
30
|
+
}, [T, R]), l(() => {
|
|
31
31
|
if (!y || !a) return;
|
|
32
|
-
|
|
33
|
-
let t =
|
|
32
|
+
E(0), A(void 0), w.current = Date.now();
|
|
33
|
+
let t = w.current, n = {
|
|
34
34
|
url: a,
|
|
35
35
|
cMapPacked: o?.isCompressed ?? !0,
|
|
36
36
|
...o?.url && { cMapUrl: o.url },
|
|
37
|
-
...
|
|
38
|
-
...
|
|
39
|
-
...
|
|
40
|
-
...
|
|
41
|
-
...
|
|
42
|
-
...
|
|
37
|
+
...j && { password: j },
|
|
38
|
+
...z !== void 0 && { disableAutoFetch: z },
|
|
39
|
+
...B !== void 0 && { disableStream: B },
|
|
40
|
+
...V !== void 0 && { rangeChunkSize: V },
|
|
41
|
+
...H !== void 0 && { withCredentials: H },
|
|
42
|
+
...U !== void 0 && { httpHeaders: U },
|
|
43
43
|
...b && { wasmUrl: b },
|
|
44
|
+
...x && { standardFontDataUrl: x },
|
|
44
45
|
verbosity: f.VerbosityLevel.ERRORS
|
|
45
46
|
};
|
|
46
47
|
try {
|
|
47
48
|
let i = f.getDocument(n);
|
|
48
49
|
i.onProgress = (e) => {
|
|
49
|
-
if (t ===
|
|
50
|
+
if (t === w.current) {
|
|
50
51
|
let { loaded: t, total: n } = e;
|
|
51
|
-
|
|
52
|
+
E(n ? Math.min(100, Math.round(t / n * 100)) : 0);
|
|
52
53
|
}
|
|
53
|
-
},
|
|
54
|
-
let a = i.promise.then(async (n) => !b && m(await n.getData()) ? (t ===
|
|
54
|
+
}, O(!0), v(void 0);
|
|
55
|
+
let a = i.promise.then(async (n) => !b && m(await n.getData()) ? (t === w.current && (v(void 0), A(e.WASM_URL_REQUIRED)), r.error(s), I?.(g()), n) : (t === w.current && (v(n), E(100)), L && L(n), F(!1), N(""), n)).catch((t) => {
|
|
55
56
|
if (t instanceof Error && t.name === "PasswordException") {
|
|
56
57
|
let e = t.code;
|
|
57
|
-
|
|
58
|
-
} else t instanceof Error && t.name === "InvalidPDFException" &&
|
|
58
|
+
F(!0), e === f.PasswordResponses.INCORRECT_PASSWORD ? N("Incorrect password") : N(void 0);
|
|
59
|
+
} else t instanceof Error && t.name === "InvalidPDFException" && j ? (F(!0), N("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (A(e.INVALID_OR_CORRUPTED_PDF), I?.(h(t))) : I && I(t);
|
|
59
60
|
}).finally(() => {
|
|
60
|
-
|
|
61
|
+
O(!1);
|
|
61
62
|
});
|
|
62
63
|
return () => {
|
|
63
64
|
a.finally(() => {
|
|
@@ -65,20 +66,21 @@ var v = (a, o, c = {}) => {
|
|
|
65
66
|
});
|
|
66
67
|
};
|
|
67
68
|
} catch (t) {
|
|
68
|
-
|
|
69
|
+
A(e.NOT_SUPPORTED), I?.(_(t));
|
|
69
70
|
}
|
|
70
71
|
}, [
|
|
71
72
|
a,
|
|
72
73
|
y,
|
|
73
74
|
b,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
I
|
|
75
|
+
x,
|
|
76
|
+
j,
|
|
77
|
+
I,
|
|
78
|
+
L
|
|
77
79
|
]), l(() => {
|
|
78
|
-
if (
|
|
80
|
+
if (P) return;
|
|
79
81
|
let n = /* @__PURE__ */ new Map();
|
|
80
|
-
if (!p ||
|
|
81
|
-
|
|
82
|
+
if (!p || D) {
|
|
83
|
+
C(n);
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
86
|
let r = p.numPages, i = [];
|
|
@@ -97,23 +99,23 @@ var v = (a, o, c = {}) => {
|
|
|
97
99
|
thumbnailScale: i,
|
|
98
100
|
defaultRotation: a.rotation
|
|
99
101
|
});
|
|
100
|
-
}),
|
|
102
|
+
}), C(n);
|
|
101
103
|
}).catch((t) => {
|
|
102
|
-
v(void 0),
|
|
104
|
+
v(void 0), A(e.INVALID_OR_CORRUPTED_PDF), I?.(h(t));
|
|
103
105
|
});
|
|
104
106
|
}, [
|
|
105
107
|
p,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
D,
|
|
109
|
+
P,
|
|
110
|
+
I
|
|
109
111
|
]), {
|
|
110
112
|
pdf: p,
|
|
111
|
-
pages:
|
|
112
|
-
loading:
|
|
113
|
-
error:
|
|
114
|
-
loadingProgress:
|
|
115
|
-
passwordRequired:
|
|
116
|
-
passwordError:
|
|
113
|
+
pages: S,
|
|
114
|
+
loading: D,
|
|
115
|
+
error: k,
|
|
116
|
+
loadingProgress: T,
|
|
117
|
+
passwordRequired: P,
|
|
118
|
+
passwordError: M
|
|
117
119
|
};
|
|
118
120
|
};
|
|
119
121
|
//#endregion
|