DEV Community

radin reth
radin reth

Posted on

1 1

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

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay