ruby-on-rails-3 - 使用 Wicked_PDF (wkhtmltopdf) 在 PDF 中嵌入 SVG

标签 ruby-on-rails-3 barcode wkhtmltopdf wicked-pdf

当我尝试在 wicked_pdf (wkhtmltopdf) 生成的 PDF 中包含 SVG 时,它显示为空白。知道如何让 svg 显示在 pdf 中吗?

app/views/barcodes/to_pdf.html.haml

<descriptive text here>
%object#code_image{:data=>"/barcodes/generate_svg?code=4567898", :type=>"image/svg+xml", :height=>70}

条码 Controller
def generate_svg
  require 'barby'
  require 'barby/barcode/code_128'
  require 'barby/outputter/svg_outputter'
  barcode = Barby::Code128B.new(params[:code])
  render :text => barcode.to_svg({:height=>30, :width => 170})
end


def to_pdf
 render :pdf        => 'file_name'      
end

最佳答案

我使用这种嵌入 SVG 的方法让它工作。

Display Inline SVG Using the Tag

代替

"data:image/svg+xml;base64,PD94bWwgdmVy..."


"data:image/svg+xml;base64,#{Base64.encode64(barcode.to_svg)}"

关于ruby-on-rails-3 - 使用 Wicked_PDF (wkhtmltopdf) 在 PDF 中嵌入 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7880079/

相关文章:

ruby-on-rails-3 - 更改 URL 而不更改资源名称

mysql - MongoDB 与 MySQL

ruby-on-rails - 在 Rails 3 中为所有具有缓存摘要的区域设置过期片段

android - 如果卡片是层压的,Android 还能读取卡片上的二维码吗?

html - 使用动态图像在 Go 中生成 PDF

ruby-on-rails - 带有谷歌网络字体的pdfkit

php - 无法在 Mac 上使用 wkhtmltopdf 打印 pdf

ruby-on-rails - 在 Rails 中,如何获取 GET 字符串并将其解析为对象?

windows-phone-8.1 - 使用 ZXing 和 MFT 在 Windows Phone 8.1 运行时上实现实时条形码扫描仪

ios - Linea Pro 条码扫描器 iPhone 问题