Git Product home page Git Product logo

pdf417's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.