lambda fonts



  • I am using jsreport hosted in AWS Lambda. I can render the report in Times New Roman font when running it from JSReport Studio on http://localhost:5488, but after deploying to lambda and running from my nodejs project, yes the .css file containing the request for Times New Roman font is active, but that particular font doesn't render. I don't understand why and not sure how to correct.

    .invoice-box {
    ...
    font-family: 'Times New Roman', 'Helvetica', Helvetica, Arial, sans-serif;
    color: #555;
    }



  • Hi,

    chrome uses OS installed fonts. You have likely the Times New Roman font installed on your local, but it isn't installed in the lambda environment.

    Adding fonts to the lambda environment seems to be possible, but not trivial. See this blog post and this SO topic. Note I haven't tried this so far.

    Another option is to try CSS web font. However not sure if you find a free Times New Roman font somewhere.

    Please share your results, if you succeed.



  • Hi Jan,

    I did get it to work without too much difficulty. It requires that I get .ttf font files from somewhere for each font I want to use. I don't recall where I got them, but here is the process once I had the .ttf files.

    In the jsreport-aws-lambda-starter-kit/data folder create a subfolder called fonts like
    jsreport-aws-lambda-starter-kit/data/fonts

    Then put your .ttf files in that folder.
    Also add a file called fonts.conf into the same fonts folder with the contents below:
    <?xml version="1.0"?>
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
    <fontconfig>
    <dir>/var/task/data/fonts/</dir>
    <cachedir>/tmp/fonts-cache/</cachedir>
    <config></config>
    </fontconfig>

    Note that /var/task is created by Lambda but is not visible to you.

    Then in the index.js file add this line after the line let jsreport

    process.env.FONTCONFIG_PATH='/var/task/data/fonts'

    After that, re-run node createLambdaPackage.js per https://jsreport.net/learn/aws-lambda-serverless

    Then (re) upload the zip file to your lambda function. With the addition of the .ttf files, your project will probably get a message like "The deployment package of your Lambda function "xxxxxJsreport" is too large to enable inline code editing. However, you can still invoke your function." This is unpleasant, but the fonts do work now. Here showing a unique font to prove that it works.

    .invoice-box {
    ...
    font-family: 'Goudy Stout', 'Helvetica', Helvetica, Arial, sans-serif;
    color: #555;
    }

    0_1624939940632_upload-5485ea02-a21e-457d-a764-d4d75f298028



  • This post is deleted!


  • Excellent! Thank you for sharing.

    We will later try this out and add it to the documentation.

    ...One thought that popped up when reading the steps is if the ttf font wouldn't work also when simply uploaded as jsreport asset.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.