我在用着邪恶_pdf使用 Rails 3.2.11 和 ruby 1.9.3 从 HTML 生成 PDF 并部署到 Heroku。
我的 pdf.css.scss.erb:
<% app_fullhost = Constants["app_fullhost"] %>
@font-face {
font-family:'DosisMedium'; font-style:normal; font-weight:500;
src: url(<%=app_fullhost%>/app/font/dosis/Dosis-Medium.ttf) format('woff');
}
*, body {
font-family: "DosisLight", 'Times New Roman', 'Arial', sans-serif;
}
where app_fullhost
是开发或生产中的确切宿主。
我的 pdf 布局包括:
%html{:lang => I18n.locale}
%head
%meta{:charset => "utf-8"}
%title= content_for?(:title) ? yield(:title) : Settings.app_name
= wicked_pdf_stylesheet_link_tag "pdf"
在生产中.rb 我有
config.assets.precompile +=%w(pdf.css)
这在开发中没有问题,但在 Heroku 上,pdf 文件无法加载所需的字体。我还尝试了不同的解决方案,例如在 production.rb 中添加这些解决方案:
config.assets.paths << "#{Rails.root}/app/assets/fonts"
config.assets.precompile += %w(*.svg *.eot *.woff *.ttf)
config.assets.precompile += %w(.svg .eot .woff .ttf)
我也尝试更改(在 pdf.css.scss.erb 中):
@font-face {
font-family:'Dosis'; font-style:normal; font-weight:500;
src: url('Dosis-Medium.ttf') format('woff');
}
or
@font-face {
font-family:'Dosis'; font-style:normal; font-weight:500;
src: url(<%= asset_path('Dosis-Medium.ttf')%>) format('woff');
}
字体位于assets/fonts
并且也在public/app/font/dosis
Heroku 上的 url 正确响应:
..//myapp/app/font/dosis/Dosis-Medium.ttf" and
..//myapp/assets/Dosis-Medium.ttf
如何在 Heroku 上加载字体?