I have an AWS Lambda function that generates PDFs using the html-pdf
library with custom fonts.
At first, I imported my fonts externally from Google Fonts, but then the PDF's size has enlarged by ten times.
So I tried to import my fonts locally src('file:///var/task/fonts/...ttf/woff2')
but still no luck.
Lastly, I trie to create fonts
folder in the main project and then I added all of my fonts, plus the file fonts.config
:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/var/task/fonts/</dir>
<cachedir>/tmp/fonts-cache/</cachedir>
<config></config>
</fontconfig>
and set the following env:
FONTCONFIG_PATH = /var/task/fonts
but still no luck (I haven't installed fontconfig since I'm not sure how and if I need to).
My Runtime env is Node.js 8.1.0.
You can upload your fonts into an S3 bucket and then download them to the lambda's
/tmp
directory, during its execution. In case your lib creates.pkl
files, you should first change your root directory to/tmp
(lambda is not allowed to write in the default root directory). The following Python code downloads your files from a/fonts
directory in an S3 bucket to/tmp/fonts
"local" directory.