I've tried many gems for creating PDF documents, some of them work really well without too much difficulty. My mission is to create a QRcode in a PDF document. I've tried a lot of combinations between QR generators and PDF generators. Although I'm having a lot of trouble actually getting the Qr code into the PDF document. I'm using the rqrcode
gem, I like it because it generates QR codes from CSS, not an image.
I've tried using gems specifically built for generating QR codes with Prawn, however I keep getting a message saying that it doesn't recognise the modules
method. The closest I've got is by using a similar structure in my html
document. But thats only using it without a table, which is useless because the gem works by outputting a table and CSS.
I know this is quite vague, but because of the amount of possible solutions and different attempts I've tried I'm not sure what other information I should give.
Any ideas? Has anyone else managed to create a QR code with the rqrcode
gem using a table in Prawn?
How the table looks in the view (HTML, not PDF):
<table class="qr">
<% qr.modules.each_index do |x| -%>
<tr>
<% qr.modules.each_index do |y| -%>
<% if qr.dark?(x,y) -%>
<td class="black"/>
<% else -%>
<td class="white"/>
<% end -%>
<% end -%>
</tr>
<% end -%>
</table>
The closest I've come without it breaking in the .prawn.pdf file
(when I try to add a table it breaks). The *
and !
is just testing that the modules method
works, when I try to change it to cell background it breaks.
@qr.modules.each_index do |x|
@qr.modules.each_index do |y|
if @qr.dark?(x,y)
pdf.text "!"
else
pdf.text "*"
end
end
end
Gemfile
gem 'prawn'
gem 'prawn-qrcode'
gem "rqrcode", "~> 0.4.2"
Update
I found some useful code, although now the problem I have is the actual sizing of the QR code. I want to be able to make the QR code very big. Surprisingly enough the parameters in the new code don't actually change the size; the size
parameter inside the actual QR code does change the size very slightly, but it's actually changing the version of the QR code, which is not what I want.