Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Offset is outside the bounds of the DataView #3042

Open
DanielLeberle opened this issue Jan 21, 2025 · 1 comment
Open

RangeError: Offset is outside the bounds of the DataView #3042

DanielLeberle opened this issue Jan 21, 2025 · 1 comment

Comments

@DanielLeberle
Copy link

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
@vimarrow
Copy link

vimarrow commented Feb 7, 2025

Got the same issue. I was also trying to get the woff2 format directly from google, but it failed, so I downloaded in the ttf format, did this:

Font.register({
  family: 'Roboto',
  fonts: [
    {
      src: '/static/fonts/Roboto-Regular.ttf',
      fontWeight: 400,
    },
    {
      src: '/static/fonts/Roboto-Bold.ttf',
      fontWeight: 700,
    }
  ]
});

and it worked afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants