@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, licenseKey: d, ...f } = a, { workerUrlAdded: p } = r(l);
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: d,
11
+ licenseKey: f,
12
12
  children: /* @__PURE__ */ i(e, {
13
- workerUrlAdded: p,
13
+ workerUrlAdded: m,
14
14
  wasmUrl: u,
15
- ...f,
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, {
@@ -378,6 +378,7 @@ export interface PdfProperties {
378
378
  export interface ConfigContextType {
379
379
  workerUrlAdded: boolean;
380
380
  wasmUrl?: string;
381
+ standardFontDataUrl?: string;
381
382
  }
382
383
  export declare enum ThemeVariables {
383
384
  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-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(), [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, 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
- L && L(w);
30
- }, [w, L]), l(() => {
29
+ R && R(T);
30
+ }, [T, R]), l(() => {
31
31
  if (!y || !a) return;
32
- T(0), k(void 0), C.current = Date.now();
33
- let t = C.current, n = {
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
- ...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
+ ...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 === C.current) {
50
+ if (t === w.current) {
50
51
  let { loaded: t, total: n } = e;
51
- T(n ? Math.min(100, Math.round(t / n * 100)) : 0);
52
+ E(n ? Math.min(100, Math.round(t / n * 100)) : 0);
52
53
  }
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) => {
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
- 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);
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
- D(!1);
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
- k(e.NOT_SUPPORTED), F?.(_(t));
69
+ A(e.NOT_SUPPORTED), I?.(_(t));
69
70
  }
70
71
  }, [
71
72
  a,
72
73
  y,
73
74
  b,
74
- A,
75
- F,
76
- I
75
+ x,
76
+ j,
77
+ I,
78
+ L
77
79
  ]), l(() => {
78
- if (N) return;
80
+ if (P) return;
79
81
  let n = /* @__PURE__ */ new Map();
80
- if (!p || E) {
81
- S(n);
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
- }), S(n);
102
+ }), C(n);
101
103
  }).catch((t) => {
102
- v(void 0), k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t));
104
+ v(void 0), A(e.INVALID_OR_CORRUPTED_PDF), I?.(h(t));
103
105
  });
104
106
  }, [
105
107
  p,
106
- E,
107
- N,
108
- F
108
+ D,
109
+ P,
110
+ I
109
111
  ]), {
110
112
  pdf: p,
111
- pages: x,
112
- loading: E,
113
- error: O,
114
- loadingProgress: w,
115
- passwordRequired: N,
116
- passwordError: j
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
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.0",
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": [