Embed custom font in Rails 6
radin reth

radin reth @radinreth

About: Open for Learning <Learning /> Workplace is a second home. Everyone is your workplace are also your family members Respect them!

Location:
Phnom Penh, Cambodia
Joined:
Jan 7, 2021

Embed custom font in Rails 6

Publish Date: Aug 10 '21
7 0

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

Comments 0 total

    Add comment