Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better documentation on how to use with prawn #3

Open
jpaas opened this issue Jun 11, 2014 · 2 comments
Open

better documentation on how to use with prawn #3

jpaas opened this issue Jun 11, 2014 · 2 comments

Comments

@jpaas
Copy link

jpaas commented Jun 11, 2014

Through some trial and error and clues left hanging in the interwebs, I only got it to work as follows by using to_png...

barcode = PDF417.new("my data to encode")
data = StringIO.new(barcode.to_png)
pdf.image(data)
@jpaas
Copy link
Author

jpaas commented Jun 11, 2014

Another tip... I wanted to centre the barcode in the PDF, and then advance my cursor afterwards. So by looking at the code I saw how the width is calculated...

x_scale = 2
y_scale = 10
margin = 0
barcode = PDF417.new("my data to encode")
data = StringIO.new(barcode.to_png(margin: margin, x_scale: x_scale, y_scale: y_scale))
barcode_width = barcode.bit_columns * x_scale + margin * 2 
image = pdf.image(data, at: [(pdf.bounds.width - barcode_width) / 2, pdf.cursor])
pdf.move_down(image.height)

@Xosmond
Copy link

Xosmond commented Jul 30, 2017

On my case I just did this on prawn document:

barcode = StringIO.new(PDF417.new("my data to encode").to_png)
image barcode, width: 200, height: 35

Because i don't need special coordinates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants