Wicked_pdf: Custom fonts not working locally

Created on 24 Apr 2019  路  1Comment  路  Source: mileszs/wicked_pdf

Issue description

wicked_pdf_stylesheet_link_tag seems to incorrectly handle urls when executed locally.

Expected or desired behavior

Given following original style (rails scss):

@font-face {
  font-family: 'MyFont';
  src: font-url('my-font/my-font.eot') format('eot')
}

which sprockets renders as:

@font-face {
  font-family: 'MyFont';
  src: url(/assets/my-font/my-font-<digest>.eof) format('eot')
}

wicket_pdf_stylesheet_link_tag renders:

@font-face {
  font-family: 'MyFont';
  src: url(file://<Rails.root>/public/assets/my-font/my-font-<digest>.eof) format('eot')
}

Which is incorrect as assets has not been precompiled in development.

I'd expect it to use the source file instead:

@font-face {
  font-family: 'MyFont';
  src: url(file://<Rails.root>/app/assets/my-font/my-font.eof) format('eot')
}

System specifications

wicked_pdf gem version: 1.2.2

wkhtmltopdf version: 0.12.3

whtmltopdf provider gem and version if one is used:

platform/distribution and version: Ubuntu 18.04.2 LTS

Most helpful comment

I think that the cause of your problem is mentioned here.

I manage to use Google's custom font poppins with the help of Issue #334 this is what I did:

1) I have the font in OTF format located in assets/fonts/poppins/Poppins-Regular.otf

2) I declared the font-face in the CSS I am importing in my pdf.

pdf.scss.erb

@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 300;
  src: url('<%= asset_data_uri('poppins/Poppins-Regular.otf') %>')
}

body {
  font-family: 'Poppins';
}

I am using ERB to get the URI of the asset automatically with the helper asset_data_uri

You need to add the fonts path to the assets path to avoid adding "fonts" to the asset_data_uri path

Application.rb

config.assets.paths << Rails.root.join("app", "assets", "fonts")

Hope this helps.

>All comments

I think that the cause of your problem is mentioned here.

I manage to use Google's custom font poppins with the help of Issue #334 this is what I did:

1) I have the font in OTF format located in assets/fonts/poppins/Poppins-Regular.otf

2) I declared the font-face in the CSS I am importing in my pdf.

pdf.scss.erb

@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 300;
  src: url('<%= asset_data_uri('poppins/Poppins-Regular.otf') %>')
}

body {
  font-family: 'Poppins';
}

I am using ERB to get the URI of the asset automatically with the helper asset_data_uri

You need to add the fonts path to the assets path to avoid adding "fonts" to the asset_data_uri path

Application.rb

config.assets.paths << Rails.root.join("app", "assets", "fonts")

Hope this helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lsarni picture lsarni  路  5Comments

EdouardPan picture EdouardPan  路  6Comments

olleolleolle picture olleolleolle  路  4Comments

amerritt14 picture amerritt14  路  4Comments

BlakeWard picture BlakeWard  路  3Comments