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

I keep getting "Error: ENOENT: no such file or directory" regarding default font files while trying to use pdfkit in a lambda function. #1441

Open
Wet-Bones opened this issue Apr 1, 2023 · 6 comments

Comments

@Wet-Bones
Copy link

When I try to generate a pdf, my console returns:

ERROR Error: ENOENT: no such file or directory, open 'C:\Users\Me\Project\.sst\artifacts\dev-app-ApiStack-api-Lambda_POST_-doc\services\functions/data/Helvetica.afm'

The only thing I've specified in the code as far as font is to use Helvetica and Helvetica-Bold at certain locations. Does the issue have to do with my __dirname?

  • pdfkit version: 0.13.0
  • Node version: 0.16.0
  • Operating System: Windows 11
@RobCabrera
Copy link

RobCabrera commented Apr 10, 2023

@Wet-Bones

Try using the environment variable in lambda - ${process.env.LAMBDA_TASK_ROOT} . It gives you the path to your lambda function.

Source: https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime

Example:
const logo = ${process.env.LAMBDA_TASK_ROOT}/pdfhandler/assets/logo.png;

@SimtecConsult
Copy link

I'm getting the same error trying to generate a new PDF in a NextJS 13 API route. Did you ever find a resolution to this issue?

@Wet-Bones
Copy link
Author

I'm getting the same error trying to generate a new PDF in a NextJS 13 API route. Did you ever find a resolution to this issue?

So I ended up downloading fonts as ttf files and storing them in the project directory. In order for them to be deployed properly, you have to configure that API route to copy the files to your assets bucket. The nodejs format must also be in cjs I believe.

@SimtecConsult
Copy link

That's good to know, I ended up putting the API route under the pages directory and it seems to work.

@Finkes
Copy link

Finkes commented Sep 22, 2023

I'm getting the same error trying to generate a new PDF in a NextJS 13 API route. Did you ever find a resolution to this issue?

Same here... any ideas how to resolve this? Switching to pages is not an option for me.

@laszlo1337
Copy link

This is probably the same problem as in my case: #1491 and it's due to PDFKit not being compatible with ESM

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

5 participants