[英]Render Prawn pdf and rqrcode display QR with Ruby on rails
Creating Ruby on rails web application with qrcode display QR code in pdf 使用qrcode在pdf中显示QR码创建Ruby on Rails Web应用程序
Iam using 我在用
gem 'rqrcode-with-patches', require: 'rqrcode'
gem 'prawn'
My post Controller to show pdf view 我的帖子控制器显示pdf视图
def show
@qr=RQRCode::QRCode.new(request.url)
respond_to do |format|
format.html
format.pdf do
pdf = PostPdf.new(@post)
send_data pdf.render, filename: "post#{@post.id}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end
post_pdf post_pdf
class PostPdf < Prawn::Document
def initialize(post)
super({top_margin: 30, page_size: 'A4', page_layout: :landscape })
@post = post
post_id
post_title
qr_code
end
def post_id
move_down 10
text "Post id: #{@post.id}"
end
def post_title
move_down 10
text "Post title: #{@post.title}"
end
def qr_code
move_down 10
@qr=RQRCode::QRCode.new(request.url)
end
end
i got error on display pdf, it's show 我在显示pdf时出现错误,这表明
undefined local variable or method `request' for #
#的未定义局部变量或方法`request'
There is a gem called prawn-qrcodes its really single to use. 有一个名为prawn-qrcodes的gem,它真的可以使用。
require 'prawn/qrcodes'
Prawn::Document.generate("qr-big.pdf") do
msg = "Hello world, this is a QR code"
text msg
qrcode msg, :position => :center,
:fit => [bounds.height, bounds.width]
end
I think that this will work better for you than ** rqrcode-with-patches** because it was build for prawn 我认为这对您比** rqrcode-with-patches **更好,因为它是为虾而建的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.