Sha256: 1a24fccec5f48f14c315ac8243c837ae8fd0c19a7f3f00829002233a6c0fb63a

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Zebra
  class PrintJob
    # class UnknownPrinter < StandardError
    #   def initialize(printer)
    #     super("Could not find a printer named #{printer}")
    #   end
    # end

    attr_reader :printer

    def initialize(printer)
      #check_existent_printers printer

      @printer = printer
    end

    def print(label, ip)
      @remote_ip = ip
      tempfile = label.persist
      send_to_printer tempfile.path
    end

    private

    # def check_existent_printers(printer)
    #   existent_printers = Cups.show_destinations
    #   raise UnknownPrinter.new(printer) unless existent_printers.include?(printer)
    # end

    def send_to_printer(path)
      puts "* * * * * * * * * * * * Sending file to printer #{@printer} at #{@remote_ip} * * * * * * * * * * "
      result = system("rlpr -H #{@remote_ip} -P #{@printer} -o #{path} 2>&1") # try printing to LPD on windows machine first
      system("lp -h #{@remote_ip} -d #{@printer} -o raw #{path}") if !result # print to unix (CUPS) if rlpr failed
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zebra-zpl-1.0.5 lib/zebra/print_job.rb