Class: PDFDirectPrint::RawPrint

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfdprint/raw_print.rb

Overview

Raw network printing using TCP port 9100 of network-enabled printer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RawPrint

Returns a new instance of RawPrint.



9
10
11
12
# File 'lib/pdfdprint/raw_print.rb', line 9

def initialize(options)
  @options = options
  @pjl = setup_pjl
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



7
8
9
# File 'lib/pdfdprint/raw_print.rb', line 7

def error_message
  @error_message
end

Instance Method Details



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pdfdprint/raw_print.rb', line 14

def print(file)
  s = TCPSocket.open(@options[:printer], @options[:port])
  @pjl.each do |_key, command|
    s.syswrite(command)
  end
  File.open(file, 'rb') do |f|
    f.binmode
    s.syswrite(f.read)
  end
  s.syswrite("#{27.chr}%-12345X")
  s.flush
  s.close
  true
rescue StandardError => e
  @error_message = e.message
  false
end