Giter Site home page Giter Site logo

cupsffi's Introduction

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.

Author

Nathan Ehresman www.tebros.com

License

CupsFFI is MIT licensed.

Installation

gem install cupsffi

Setup

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 = CupsPrinter.new(printers.first)

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

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

# 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]
job.status

# Cancel a specific job
job.cancel

# 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
printer.cancel_all_jobs

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.example.com')
print = CupsPrinter.new(remote_printers.first, :hostname => 'print.example.com')

cupsffi's People

Contributors

huerlisi avatar jslabovitz avatar nehresma avatar

Watchers

 avatar

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.