diegomura / diegomura/react-pdf

RangeError: Offset is outside the bounds of the DataView

Open
#3,042 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
16.8k
Forks
1.3k
Avg merge
5h 6m
Merged PRs (30d)
52

Description

**Describe the bug**
I'm trying to import the google font Hanken Grotesk to use it creating a PDF in one of my firebase cloud functions. When the PDF is created unfortunately I get the error

>Error encoding PDF: RangeError: Offset is outside the bounds of the DataView
> at DataView.setUint16 ()
> at $fe042f4b88f46896$export$2e2bcd8739ae039._addGlyph (.../functions/node_modules/fontkit/dist/main.cjs:12176:22)
> at $fe042f4b88f46896$export$2e2bcd8739ae039.encode (.../functions/node_modules/fontkit/dist/main.cjs:12209:43)
> at EmbeddedFont.embed (/Users/danielleberle/Projekte/kinderkueche/Kinderkueche-Order-App/functions/node_modules/@react-pdf/pdfkit/lib/pdfkit.cjs:36382:30)
> at EmbeddedFont.finalize (.../functions/node_modules/@react-pdf/pdfkit/lib/pdfkit.cjs:36523:10)
> at PDFDocument.end (.../functions/node_modules/@react-pdf/pdfkit/lib/pdfkit.cjs:38716:12)
> at Object.render [as default] (.../functions/node_modules/@react-pdf/render/lib/index.cjs:2009:7)
> at _callee$ (.../functions/node_modules/@react-pdf/renderer/lib/react-pdf.cjs.js:4133:55)
> at tryCatch (.../functions/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:45:16)
> at Generator. (.../functions/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:133:17)

The URL to the font is:

https://fonts.gstatic.com/s/hankengrotesk/v8/ieVq2YZDLWuGJpnzaiwFXS9tYvBRzyFLlZg_f_Ncs2Zq5vBM73tBKQ.woff2

It works with other fonts, so it might be a problem with the font file but I'm not sure.

When I try to use the font from a different source as TTF (https://github.com/marcologous/hanken-grotesk/blob/master/fonts/ttf/HankenGrotesk-Medium.ttf) I get a different error:

> Error encoding PDF: Error: Unknown font format
> at Object.$59aa4ed98453e1d4$export$185802fd694ee1f5 (.../functions/node_modules/fontkit/dist/main.cjs:57:11)
> at FontSource._load (.../functions/node_modules/@react-pdf/font/lib/index.cjs:95:38)
> at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Is there anything I can do or should I search for other font sources?

**Desktop (please complete the following information):**

- OS: MacOS
- node 18.18.0
- react-pdf/renderer: 3.1.15

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.