barcodes-code128-0.1.0: Generate Code 128 barcodes as PDFs

Safe HaskellNone



A library for generating barcodes in Code 128. Details of the encoding are available at The width of the stripes and the height of the barcode are configurable. Two modes of operation are supported:

  • Constructing a PDF directly in a ByteString, and
  • Constructing an action in HPDF's Draw monad, for composing the barcode with other information in a PDF.



data BarcodeConfig Source

Controls the size of the generated barcode. All units are in HPDF's internal sizing.




height :: Double

The height of the generated barcode

barWidth :: Double

The width of the narrowest possible bar

data Err Source

Errors that can occur while constructing a barcode


CantEncode Char

The returned character cannot be encoded in Code 128


barcodeSize :: BarcodeConfig -> [Char] -> Either Err (Double, Double) Source

Determine the width and height of rendering a particular string as a barcode in a particular configuration.

barcodePDF :: BarcodeConfig -> String -> IO ByteString Source

Generate PDF data containing the barcode for a given string, with the tightest possible bounding box. If the string cannot be encoded in Code 128, an IOError is thrown.

drawBarcode Source


:: BarcodeConfig

How to render the barcode

-> String

The string to encode

-> Point

The origin (lower left) of the barcode on the page

-> Either Err (Draw Point) 

Encode a string and construct an action in Draw that will render it as a barcode. The action, if created successfully, will return the opposite corner of the barcode. An error is returned if the string could not be encoded as a Code128 barcode.