@react-pdf-kit/viewer 2.8.0 → 2.9.0-beta.1

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,15 @@ 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, licenseKey: d, ...f } = a, { workerUrlAdded: p } = r(l);
9
+ let { children: o, customVariables: s, customDarkVariables: c, workerUrl: l, wasmUrl: u, iccUrl: d, standardFontDataUrl: f, licenseKey: p, ...m } = a, { workerUrlAdded: h } = r(l);
10
10
  return /* @__PURE__ */ i(t, {
11
- licenseKey: d,
11
+ licenseKey: p,
12
12
  children: /* @__PURE__ */ i(e, {
13
- workerUrlAdded: p,
13
+ workerUrlAdded: h,
14
14
  wasmUrl: u,
15
- ...f,
15
+ iccUrl: d,
16
+ standardFontDataUrl: f,
17
+ ...m,
16
18
  children: /* @__PURE__ */ i(n, {
17
19
  customDarkVariables: c,
18
20
  customVariables: s,
@@ -3,7 +3,9 @@ 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
+ iccUrl: void 0,
8
+ standardFontDataUrl: void 0
7
9
  }), i = () => t(r), a = (e) => {
8
10
  let { children: t, ...i } = e;
9
11
  return /* @__PURE__ */ n(r.Provider, {
@@ -378,6 +378,8 @@ export interface PdfProperties {
378
378
  export interface ConfigContextType {
379
379
  workerUrlAdded: boolean;
380
380
  wasmUrl?: string;
381
+ iccUrl?: string;
382
+ standardFontDataUrl?: string;
381
383
  }
382
384
  export declare enum ThemeVariables {
383
385
  FONT_FAMILY = "--rp-font-family",
@@ -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-07T11:59:04.036Z"), 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 = {
6
+ var o = /* @__PURE__ */ new Date("2026-08-11T04:21:17.805Z"), 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,45 @@ 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(), [x, S] = d(/* @__PURE__ */ new Map()), C = u(), [w, T] = d(0), [E, D] = d(!1), [O, k] = d(), { password: A, passwordError: j, setPasswordError: M, passwordRequired: N, setPasswordRequired: P } = i(), { onLoadError: F, onLoaded: I, onLoadProgress: L, disableAutoFetch: R, disableStream: z, rangeChunkSize: B, withCredentials: V, httpHeaders: H } = c;
27
+ let [p, v] = d(), { workerUrlAdded: y, wasmUrl: b, iccUrl: x, standardFontDataUrl: S } = n(), [C, w] = d(/* @__PURE__ */ new Map()), T = u(), [E, D] = d(0), [O, k] = d(!1), [A, j] = d(), { password: M, passwordError: N, setPasswordError: P, passwordRequired: F, setPasswordRequired: I } = i(), { onLoadError: L, onLoaded: R, onLoadProgress: z, disableAutoFetch: B, disableStream: V, rangeChunkSize: H, withCredentials: U, httpHeaders: W } = c;
28
28
  return l(() => {
29
- L && L(w);
30
- }, [w, L]), l(() => {
29
+ z && z(E);
30
+ }, [E, z]), l(() => {
31
31
  if (!y || !a) return;
32
- T(0), k(void 0), C.current = Date.now();
33
- let t = C.current, n = {
32
+ D(0), j(void 0), T.current = Date.now();
33
+ let t = T.current, n = {
34
34
  url: a,
35
35
  cMapPacked: o?.isCompressed ?? !0,
36
36
  ...o?.url && { cMapUrl: o.url },
37
- ...A && { password: A },
38
- ...R !== void 0 && { disableAutoFetch: R },
39
- ...z !== void 0 && { disableStream: z },
40
- ...B !== void 0 && { rangeChunkSize: B },
41
- ...V !== void 0 && { withCredentials: V },
42
- ...H !== void 0 && { httpHeaders: H },
37
+ ...M && { password: M },
38
+ ...B !== void 0 && { disableAutoFetch: B },
39
+ ...V !== void 0 && { disableStream: V },
40
+ ...H !== void 0 && { rangeChunkSize: H },
41
+ ...U !== void 0 && { withCredentials: U },
42
+ ...W !== void 0 && { httpHeaders: W },
43
43
  ...b && { wasmUrl: b },
44
+ ...x && {
45
+ iccUrl: x,
46
+ useWorkerFetch: !0
47
+ },
48
+ ...S && { standardFontDataUrl: S },
44
49
  verbosity: f.VerbosityLevel.ERRORS
45
50
  };
46
51
  try {
47
52
  let i = f.getDocument(n);
48
53
  i.onProgress = (e) => {
49
- if (t === C.current) {
54
+ if (t === T.current) {
50
55
  let { loaded: t, total: n } = e;
51
- T(n ? Math.min(100, Math.round(t / n * 100)) : 0);
56
+ D(n ? Math.min(100, Math.round(t / n * 100)) : 0);
52
57
  }
53
- }, D(!0), v(void 0);
54
- let a = i.promise.then(async (n) => !b && m(await n.getData()) ? (t === C.current && (v(void 0), k(e.WASM_URL_REQUIRED)), r.error(s), F?.(g()), n) : (t === C.current && (v(n), T(100)), I && I(n), P(!1), M(""), n)).catch((t) => {
58
+ }, k(!0), v(void 0);
59
+ let a = i.promise.then(async (n) => !b && m(await n.getData()) ? (t === T.current && (v(void 0), j(e.WASM_URL_REQUIRED)), r.error(s), L?.(g()), n) : (t === T.current && (v(n), D(100)), R && R(n), I(!1), P(""), n)).catch((t) => {
55
60
  if (t instanceof Error && t.name === "PasswordException") {
56
61
  let e = t.code;
57
- P(!0), e === f.PasswordResponses.INCORRECT_PASSWORD ? M("Incorrect password") : M(void 0);
58
- } else t instanceof Error && t.name === "InvalidPDFException" && A ? (P(!0), M("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t))) : F && F(t);
62
+ I(!0), e === f.PasswordResponses.INCORRECT_PASSWORD ? P("Incorrect password") : P(void 0);
63
+ } else t instanceof Error && t.name === "InvalidPDFException" && M ? (I(!0), P("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (j(e.INVALID_OR_CORRUPTED_PDF), L?.(h(t))) : L && L(t);
59
64
  }).finally(() => {
60
- D(!1);
65
+ k(!1);
61
66
  });
62
67
  return () => {
63
68
  a.finally(() => {
@@ -65,20 +70,22 @@ var v = (a, o, c = {}) => {
65
70
  });
66
71
  };
67
72
  } catch (t) {
68
- k(e.NOT_SUPPORTED), F?.(_(t));
73
+ j(e.NOT_SUPPORTED), L?.(_(t));
69
74
  }
70
75
  }, [
71
76
  a,
72
77
  y,
73
78
  b,
74
- A,
75
- F,
76
- I
79
+ x,
80
+ S,
81
+ M,
82
+ L,
83
+ R
77
84
  ]), l(() => {
78
- if (N) return;
85
+ if (F) return;
79
86
  let n = /* @__PURE__ */ new Map();
80
- if (!p || E) {
81
- S(n);
87
+ if (!p || O) {
88
+ w(n);
82
89
  return;
83
90
  }
84
91
  let r = p.numPages, i = [];
@@ -97,23 +104,23 @@ var v = (a, o, c = {}) => {
97
104
  thumbnailScale: i,
98
105
  defaultRotation: a.rotation
99
106
  });
100
- }), S(n);
107
+ }), w(n);
101
108
  }).catch((t) => {
102
- v(void 0), k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t));
109
+ v(void 0), j(e.INVALID_OR_CORRUPTED_PDF), L?.(h(t));
103
110
  });
104
111
  }, [
105
112
  p,
106
- E,
107
- N,
108
- F
113
+ O,
114
+ F,
115
+ L
109
116
  ]), {
110
117
  pdf: p,
111
- pages: x,
112
- loading: E,
113
- error: O,
114
- loadingProgress: w,
115
- passwordRequired: N,
116
- passwordError: j
118
+ pages: C,
119
+ loading: O,
120
+ error: A,
121
+ loadingProgress: E,
122
+ passwordRequired: F,
123
+ passwordError: N
117
124
  };
118
125
  };
119
126
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "2.8.0",
3
+ "version": "2.9.0-beta.1",
4
4
  "private": false,
5
5
  "description": "A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.",
6
6
  "keywords": [