Module: PrintDrivers

Includes:
Exceptions
Included in:
OxPrintJob
Defined in:
lib/print_drivers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/print_drivers.rb', line 15

def self.included(base)

  # build PDF or somehow prepare printer output
  def rendered_on(*args)
    begin
      update_column(:state, "rendering")

      # TODO 2013-06-08 set the action_printer with respect to the selected output & printer
      action_printer = case print_driver
      when :pdf, "pdf"
        require 'oxen_printer/pdf_printer'
        PdfPrinter.new(printer, paper)
      when :cab, "cab"
        require 'oxen_printer/cab_printer'
        CabPrinter.new(printer, paper)
      when :label, "label"
        require 'oxen_printer/label_printer'
        LabelPrinter.new(printer, paper)
      when :html, "html"
        require 'oxen_printer/html_printer'
        HtmlPrinter.new(printer, paper)
      when :csv, "csv"
        require 'oxen_printer/csv_printer'
        CsvPrinter.new(printer, paper)
      end
    rescue => e
      logit :error, "assigning printer driver failed - #{e.message}"
      return nil
    end

    # print_job.action_printer.printer = print_job.printer
    # print_job.cycle if
    return action_printer if action_printer.do_render(self,args)
    nil
  end

  #
  # called from the perform on the print_job
  # print_with will use the action_printer to build the print
  # and return the resulting filepath
  #
  def print_with action_printer
    update_column(:state, "printing")
    if action_printer && action_printer.do_print(copies)
      update_column(:state, 'done')
      action_printer.file_path
    else
      update_column(:state, 'error printing')
      raise PrintJobPrintingError
    end
  end

  def send_with action_printer, context
    begin
      update_column(:state, 'sending')
      if action_printer && action_printer.send_print_file( context)
        update_column(:state, 'done')
        action_printer.file_path
      else
        update_column(:state, 'error sending')
        raise PrintJobPrintingError
      end
    rescue => e
    end
  end

  # q%{
  #   Problem with CUPS printer definitions - losing knowledge of attached printers
  #
  #   D [08/Dec/2008:16:20:25 +0100] cupsdAuthorize: No authentication data provided.
  #   D [08/Dec/2008:16:20:25 +0100] Print-Job ipp://localhost/printers/HP_LaserJet_M3035_MPF_192.168.105.78
  #   D [08/Dec/2008:16:20:25 +0100] print_job: auto-typing file...
  #   D [08/Dec/2008:16:20:25 +0100] print_job: request file type is application/pdf.
  #   D [08/Dec/2008:16:20:25 +0100] Print-Job client-error-not-found: The printer or class was not found.
  #   D [08/Dec/2008:16:20:25 +0100] cupsdProcessIPPRequest: 8 status_code=406 (client-error-not-found)
  #   D [08/Dec/2008:16:20:25 +0100] cupsdCloseClient: 8
  #
  # }
end

Instance Method Details

called from the perform on the print_job print_with will use the action_printer to build the print and return the resulting filepath



56
57
58
59
60
61
62
63
64
65
# File 'lib/print_drivers.rb', line 56

def print_with action_printer
  update_column(:state, "printing")
  if action_printer && action_printer.do_print(copies)
    update_column(:state, 'done')
    action_printer.file_path
  else
    update_column(:state, 'error printing')
    raise PrintJobPrintingError
  end
end

#rendered_on(*args) ⇒ Object

build PDF or somehow prepare printer output



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/print_drivers.rb', line 18

def rendered_on(*args)
  begin
    update_column(:state, "rendering")

    # TODO 2013-06-08 set the action_printer with respect to the selected output & printer
    action_printer = case print_driver
    when :pdf, "pdf"
      require 'oxen_printer/pdf_printer'
      PdfPrinter.new(printer, paper)
    when :cab, "cab"
      require 'oxen_printer/cab_printer'
      CabPrinter.new(printer, paper)
    when :label, "label"
      require 'oxen_printer/label_printer'
      LabelPrinter.new(printer, paper)
    when :html, "html"
      require 'oxen_printer/html_printer'
      HtmlPrinter.new(printer, paper)
    when :csv, "csv"
      require 'oxen_printer/csv_printer'
      CsvPrinter.new(printer, paper)
    end
  rescue => e
    logit :error, "assigning printer driver failed - #{e.message}"
    return nil
  end

  # print_job.action_printer.printer = print_job.printer
  # print_job.cycle if
  return action_printer if action_printer.do_render(self,args)
  nil
end

#send_with(action_printer, context) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/print_drivers.rb', line 67

def send_with action_printer, context
  begin
    update_column(:state, 'sending')
    if action_printer && action_printer.send_print_file( context)
      update_column(:state, 'done')
      action_printer.file_path
    else
      update_column(:state, 'error sending')
      raise PrintJobPrintingError
    end
  rescue => e
  end
end