alixaxel / chrome-aws-lambda

Chromium Binary for AWS Lambda and Google Cloud Functions
MIT License
3.17k stars 289 forks source link

[REQUEST] fonts for rendering special characters #243

Open fmmattioni opened 2 years ago

fmmattioni commented 2 years ago

Hi,

I have been trying, without much success, to compile an HTML template into PDF in a AWS lambda function with the correct special characters.

I have included in the head of my HTML template the following:

<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;1,400&amp;display=swap" rel="stylesheet">

and in css I have this:

html {
      -webkit-print-color-adjust: exact;
      --font-family-sans-serif: "Montserrat",Helvetica,Arial,serif;
      --font-family-monospace: "Montserrat",Helvetica,Arial,serif;
}
* {
      color: rgb(14,17,17);
      font-size: 1rem;
      font-family: "Montserrat",Helvetica,Arial,serif;
}

It renders all the fonts correctly, with the exception of this special character: , which can also be written like this in HTML: V&#775;.

Looking at the google fonts website, it looks like this font can indeed render this character: https://fonts.google.com/specimen/Montserrat?query=montserrat&preview.text=V%CC%87&preview.text_type=custom

However, my PDF is rendered as squares. I was wondering if I should be installing another font in order for this to work?

BrunoQuaresma commented 2 years ago

I'm facing the same issue, is there a way to workaround this?

piyushk96 commented 1 year ago

Here is the solution that worked for me. Download Montserrat.ttf file and place it in your project folder like my-project/fonts/Montserrat.ttf. Now set your fonts directory in FONTCONFIG_PATH environment variable as process.env.FONTCONFIG_PATH=/var/task/my-project/fonts (/var/task is the folder where lambda places your project). Deploy your function and it should work.