Including custom fonts in the .fonts folder in heroku doesn't seem to recognize them

Heroku support informed me that to use custom fonts in my web application (not installed on the system, you can see the ones installed using fc-list in the bash console) I had to expand the .fonts folder with all the fonts inside.

The problem is that I do not know how to do this. I mean, I don’t know if the file name should follow any special template for the hero, or should I do something in my code to consider these fonts, or something automatic if I include it in the folder. ..

The fact is, I tried to change the font file name differently, and the font is not used at all.

To give you more details, we used a font to convert the PDF to an image, more specifically, with the rghost gem. And the last image doesn't use a custom font at all.

Thanks in advance, any idea is welcome.

+4
source share
3 answers

I would simply create the fonts/ directory in the root folder of the project, and then load such fonts, for example, in config/initializers/rghost.rb :

 RGhost::Config::GS[:extensions] << "#{Rails.root}/fonts/LTSyntax.ttf" 

The documentation states that you will also need a Fontmap file in the font directory, for example:

 /Syntax (LTSyntax.ttf); 

Your problem is that PDF links refer to fonts that are not embedded in the PDF file. You can get a list of fonts that are used in PDF with xpdf using the pdffonts command:

 > pdffonts example.pdf name type emb sub uni object ID ------------------------------------ ----------------- --- --- --- --------- Syntax Type 1 no no no 8 0 

Alternatively, you can also use this script from a pdf reader .

+5
source

The way I did this is to put all the fonts in lib/assets/fonts .

Add these lines to config/application.rb

 config.assets.paths << Rails.root.join('lib', 'assets', 'fonts') config.assets.precompile += %w(.svg .eot .woff .ttf) 

Then I include fonts in the stylesheets in lib/assets/stylehseets/fonts.css , for each font something like:

 @font-face { font-family: 'AvenirLTStd-Black'; src: font-url('avenirltstdblack.eot'); src: font-url('avenirltstdblack.eot?#iefix') format('embedded-opentype'), font-url('avenirltstdblack.woff') format('woff'), font-url('avenirltstdblack.ttf') format('truetype'), font-url('avenirltstdblack.svg#avenirltstdblack') format('svg'); font-weight: normal; font-style: normal; } 

And include this file in app/assets/stylesheets/application.css

 *= require fonts 

In your css (scss) application, you can use:

 font-family: 'AvenirLTStd-Black'; 

Then just recompile $ rake assets:precompile and redistribute. Let me know if this works for you, might have missed the step like I did this a few months ago!

+2
source

This article seems to indicate a way to get custom fonts working in Heroku

http://www.mobalean.com/blog/2011/08/02/pdf-generation-and-heroku

The short answer is that you can:

  • Add them to the remote file system via GIT checkin
  • Use Ruby to create the $HOME/.font (if it does not already exist)
  • Use Ruby to create a symbolic link for each of the font files in the $HOME/.font , indicating the location in the file system (again, if they do not already exist)
  • Voila!
0
source

Source: https://habr.com/ru/post/1481226/


All Articles