julianhille / MuhammaraJS

Muhammara a node module with c/cpp bindings to modify PDF with js for node or electron (based/replacement on/of galkhana/hummusjs)
Other
205 stars 43 forks source link

how to use default fonts #321

Closed manjilkhambe closed 10 months ago

manjilkhambe commented 10 months ago

I am trying to add watermark to the pdf file. I don't want to provide any font path. Is there a way to do it? Please refer code below

image
julianhille commented 10 months ago

by default fonts you mean your system fonts right?

julianhille commented 10 months ago

if yes you might use os-fonts or get-system-fonts or some other similar fonts.

But be aware that this might not work ec2 or lambda instances if you do not have any access rights to some ttf or other font files or system / library folders.

Best way is to package some default fonts with your app and retrieve path from env config so anyone using your app could just add a path and change font path without editing the code.

manjilkhambe commented 10 months ago

No no, I wanted to use fonts used in library itself. I don't want to give the file path to getFontForFile function. Is there a way to achieve it ?

julianhille commented 10 months ago

i'm not sure what this exactly means. do you have a font in memory like a buffer?

manjilkhambe commented 10 months ago

Using reciepe approach I can directly use font: 'Roboto'. similarly is there a way so that I can directly provide font name - Robot | Helvetica etc fonts which are already there in the fonts folder of npm package.

please refer below code which is written in unit tests in
TestMaterials/ Reciepe/ text.js

image
julianhille commented 10 months ago

Ahhh got it. There is currently no other option besides using receipt which loads the default fonts.

manjilkhambe commented 10 months ago

okay. thanks for the reply.

julianhille commented 10 months ago

i could add a convinience function which adds a map of name -> pathes. that would make it easier. would that help?

manjilkhambe commented 10 months ago

yes. that would help I guess. Any sort of reference to the paths would do. It would be helpful in cases where user don't want to use custom fonts.