0

Im am using hummusJS to manipulate PDF Files with Firebase Cloud functions.

As far as I know, Hummus requires to have access to an actual true type font file, to be able to use fonts in PDFs. In my local env I'm using this:

https://github.com/devongovett/font-manager

It has some depends on some libfontconfig-dev, its not working on cloud functions.

According to this post there is no way to use hummus without fonts:

https://github.com/galkahana/HummusJS/issues/120

I could store the needed fonts online and download it everytime into the function, but this doesn't feel right.

Any Idea how I could make this work?

edit: I'm not picky, I would use every font beside Comic Sans

Community
  • 1
  • 1
jbb
  • 530
  • 1
  • 5
  • 17

1 Answers1

0

I managed to get the TrueType File into my package.

Just added the local file as dependency to package.json, its working on Firebase Functions.

jbb
  • 530
  • 1
  • 5
  • 17
  • hey jbb! how did you do that? adding a ttf as dependency in package.json doesnt work for me :( – dy_ Jan 26 '18 at 00:56
  • as far a I remember I did create a npm package like this: { "name": "myfonts", "version": "1.0.0", "description": "Arial font file", "main": "arial.ttf", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } I did put this under dependencies later. But I don't think this is correct and I ended up not using it. Do you use firebase functions? **I think if you just have the ttf in your functions folder it will get deployed with your functions and you can use it via file system inside your function.** – jbb Jan 26 '18 at 01:12
  • thanks for the quick reply! :) yes, i'm trying to use it in firebase functions and reference the font from node-canvas to draw on the canvas with a specific font. so i think it has to be set as a system font somehow, because only v1 of node-canvas is available on firebase functions and v1 only supports the use of installed system fonts. direct loading of fonts files was introduced in v2 :( already tried the npm packages for the specific font ("npm-font-open-sans") but this didn't help. the ttf file itself is already included in my node package. – dy_ Jan 26 '18 at 17:52
  • have you could tried this: [link](https://medium.com/@adamhooper/fonts-in-node-canvas-bbf0b6b0cabf) ? maybe it works on firebase functions aswell – jbb Jan 26 '18 at 17:56
  • thanks for your effort! i finally found a working solution. works on firebase functions and google cloud functions. i just use the following precompiled version of node-canvas: "canvas-prebuilt": "2.0.0-alpha.2" in my package.xml. alpha.3/4/5 have broken font support, but alpha.2 works fine :) – dy_ Jan 30 '18 at 21:45
  • I can confirm that just putting the font in your functions folder in Firebase works. – HixField Jun 08 '18 at 22:00