Skip to content

asee/pdf417

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdf417

A wrapper for the pdf417lib C Library, from the README:

A library to generate the 2D barcode PDF417

Project: http://pdf417lib.sourceforge.net/
Creator: Paulo Soares ([email protected])
License: LGPL or MPL 1.1

This library generates a PDF417 image of the barcode in a 1x1 scale.
It requires that the displayed image be as least stretched 3 times
in the vertical direction in relation with the horizontal dimension.

Fetching the codewords only can be handy for using rtex and the pst-barcode package. If you’re using prawn or RMagic the to_blob function should help generate a complete barcode.

Much of this was based off of reading through the Nokogiri and RMagic source code. Thanks!

Usage

There are a few ways to use the library, at its simplest:

PDF417.encode_text("readable barcode data") => [12, 827, 120, 90, 41, 146, 30, 512, 423, 146, 90, 570]

If you want to get the raw barcode data from the PDF417 library:

barcode = PDF417.new("readable barcode data")
barcode.to_blob  # oops, wrong text
barcode.text = "ACTUAL barcode data"
barcode.to_blob

If you want to get it as an array of strings (each array element representing a line)

barcode.encoding

If you want to use fixed rows or cols

barcode = PDF417.new(text: "barcode data" * 20, cols: 3) # fixed cols
barcode.to_blob
[barcode.cols, barcode.rows] # => [3, 42]
barcode = PDF417.new(text: "barcode data" * 20, rows: 2) # fixed rows
barcode.to_blob
[barcode.cols, barcode.rows] # => [30, 5]

If you want to use aspect ratio to determine rows and cols

barcode = PDF417.new(text: "barcode data" * 20, aspect_ratio: 0.618)
barcode.to_blob
[barcode.cols, barcode.rows] # => [4, 31]

If you want to change error level (maximum 8)

barcode = PDF417.new(text: "barcode data" * 20, error_level: 6)
barcode.to_blob
[barcode.cols, barcode.rows] # => [8, 32]

If you have chunky_png installed and you’d rather have a PNG

barcode.to_png # 1x1 scale
barcode.to_png(margin: 0, x_scale: 1, y_scale: 3) # stretch 3 times in the vertical direction

If you want to know the barcode image size in pixel

barcode = PDF417.new(text: "barcode data" * 20, aspect_ratio: 0.618, error_level: 6)
cimg = barcode.to_chunky_png(margin: 0, x_scale: 2, y_scale: 6)
[cimg.width, cimg.height] # => [376, 216]

If you want to use in Prawn

pdf.image(StringIO.new(barcode.to_png(margin: 0, x_scale: 2, y_scale: 6)), at: pos)
pdf.image(StringIO.new(barcode.to_chunky_png(margin: 0, x_scale: 2, y_scale: 6).to_blob), at: pos)

See the RDocs for more information.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but

    bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright © 2011 jamesprior. See LICENSE for details.

About

A Ruby wrapper for the PDF417 barcode library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •