DEV Community

radin reth
radin reth

Posted on

Embed custom font in Rails 6

Embed custom font in rails 6 is a bit tricky, below are the steps in order to embed custom font in rails 6 project especially work it works fine for wicked pdf gem

  1. Include your prefer font in app/assets/fonts/
  2. Update app/assets/config/manifest.js
...
//= link_tree ../fonts
Enter fullscreen mode Exit fullscreen mode
  1. I also create app/assets/stylesheets/embeded_fonts.scss
@font-face {
  font-family: "khmeros_battambang";
  src: font-url("khmeros_battambang.ttf") format("truetype");
}
Enter fullscreen mode Exit fullscreen mode
  1. Import to app/assets/stylesheets/application.scss
@import "embeded_fonts";
Enter fullscreen mode Exit fullscreen mode
  1. Import to layouts/pdf.html.haml
= stylesheet_link_tag "embeded_fonts"
= wicked_pdf_stylesheet_link_tag "pdf"
= wicked_pdf_javascript_pack_tag "pdf"
Enter fullscreen mode Exit fullscreen mode
  1. Call the embedded font
body {
  font-family: 'khmeros_battambang'
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)