Skip to content
libcups ffi wrapper
Branch: master
Clone or download
Latest commit 2710f8f Apr 12, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib version bump Apr 12, 2019
.gitignore ignore vim files Jan 10, 2011
COPYING Licensing. Readme Mar 6, 2011
README.rdoc Add short example for using remote cups server. Dec 5, 2012
Rakefile Initial commit Jan 10, 2011
cupsffi.gemspec remove duplicate dependency in gemspec Aug 24, 2014


CupsFFI is an FFI wrapper around libcups providing access to the Cups API as well as the PPD API. It was written using Ruby 1.9.2 but has not been tested with previous versions.


Nathan Ehresman


CupsFFI is MIT licensed.


gem install cupsffi


Nothing required. libcups is used to find and read all configuration.

Example usage

require 'cupsffi'
# Returns array of printer names:
#  => ["HP-Officejet-7200-series", "test-printer"] 
printers = CupsPrinter.get_all_printer_names

printer =

# Returns a hash of the Cups printer options:
# => {"auth-info-required"=>"none",
#     "copies"=>"1",
#     "device-uri"=>"ipp://", ...

# Return a hash of :state and :reasons.
# :state is :idle, :printing, or :stopped.  For example:
# {:state=>:idle, :reasons=>["none"]}

# Print a file (pdf, jpg, ps, etc.).  You can pass in a hash of printer
# options if you want to override the printer's defaults.  A CupsJob object
# is returned.  CupsJob can be used to check on the job status.
job = printer.print_file('/tmp/example.jpg', {'InputSlot' => 'Upper', 'PageSize' => 'A4'})

# A job's status is a CupsFFI::IppJState enumeration: 
# [:pending, :held, :processing, :stopped, :canceled, :aborted, :completed]

# Cancel a specific job

# Print a binary blob of data.  The data should be in a String, and is
# passed to libcups as a char array.  You must also specify the mime type.
# Like print_file, printer options are... optional.  A CupsJob object is
# returned.
job = printer.print_data('hello world', 'text/plain')

# Cancel all outstanding jobs on the printer

Remote CUPS Server

You may pass in :hostname and :port arguments when creating a CupsPrinter instance or querying for available printers.

remote_printers = CupsPrinter.get_all_printer_names(:hostname => '')
print =, :hostname => '')
You can’t perform that action at this time.