使用Wicked_PDF将SVG嵌入PDF(wkhtmltopdf) [英] Embedding SVG in PDF using Wicked_PDF (wkhtmltopdf)

查看:212
本文介绍了使用Wicked_PDF将SVG嵌入PDF(wkhtmltopdf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I try to include an SVG in a PDF generated by wicked_pdf (wkhtmltopdf), it comes out blank. Any idea how to get the svg to display in the 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}

条形码控制器

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的方法来使它正常工作.

I got it to work using this method of embedding SVG.

显示嵌入式SVG使用标签

替换

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

使用

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

这篇关于使用Wicked_PDF将SVG嵌入PDF(wkhtmltopdf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆