我使用的是Rails 3.2.9。我可以使用typekit (或goggle字体)来渲染图像吗?我使用了以下代码,但图像没有呈现正确的字体。我怀疑页面没有加载。
html = "<head>"
html << '<script type="text/javascript" src="//use.typekit.net/dtf1xzc.js"></script>'
html << '<script type="text/javascript">try{Typekit.load();}catch(e){}</script>'
html << "</head>"
html << html2berendered
kit = IMGKit.new(html)
kit.stylesheets << Rails.root.join('app', 'assets','stylesheets' ,'cards.css').to_s
kit.to_png或者,我可以通过安装自定义字体来尝试使用它们,但由于某种奇怪的原因,它们无法加载。
发布于 2013-01-09 10:39:49
无论如何,我意识到这是不可能的。因此,我在我的heroku机器上使用了一个非常智能的解决方案来安装自定义字体: www.mobalean.com/blog/2011/08/02/pdf-generation-and-heroku
代码如下。希望这对任何需要在heroku/wkthtmltoimage中自定义字体的人都有用
if Rails.env.production? || Rails.env.staging?
font_dir = File.join(Dir.home, ".fonts")
Dir.mkdir(font_dir) unless Dir.exists?(font_dir)
Dir.glob(Rails.root.join("vendor", "fonts", "*")).each do |font|
target = File.join(font_dir, File.basename(font))
File.symlink(font, target) unless File.exists?(target)
end
endhttps://stackoverflow.com/questions/14192694
复制相似问题