diff --git a/examples/autoprint_closing.rb b/examples/autoprint_closing.rb new file mode 100644 index 0000000..25e5873 --- /dev/null +++ b/examples/autoprint_closing.rb @@ -0,0 +1,13 @@ +require "rubygems" +$:.push File.join(File.dirname(__FILE__), "../lib") +require "prawn-print" + +FILENAME = "/tmp/prawn_autoprint_named.pdf" + +pdf = Prawn::Document.new +pdf.text "Help! I am trapped in a PDF factory!" +pdf.autoprint "LaserJet", true +pdf.render_file FILENAME + +`open -a "Adobe Reader" #{FILENAME}` if system("which open") +puts "Done." diff --git a/lib/prawn-print.rb b/lib/prawn-print.rb index 9dafccc..685d507 100644 --- a/lib/prawn-print.rb +++ b/lib/prawn-print.rb @@ -7,23 +7,23 @@ module Print include JS def print - print_with_auto_to_printer(false, nil) + print_with_auto_to_printer(false, nil, nil) end - def autoprint(printer=nil) - print_with_auto_to_printer(true, printer) + def autoprint(printer=nil, close=nil) + print_with_auto_to_printer(true, close, printer) end private - def print_with_auto_to_printer(auto, printer) + def print_with_auto_to_printer(auto, close, printer) add_docopen_js("print", <<-JS) var pp = this.getPrintParams(); #{interactive_js(auto)} #{select_printer_js(printer)} this.print(pp); - + #{close_js(close)} JS end @@ -55,6 +55,14 @@ def select_printer_js(printer) end end + def close_js(close) + if close + <<-JS + this.closeDoc(); + JS + end + end + end end diff --git a/lib/prawn-print/version.rb b/lib/prawn-print/version.rb index 4ba9eab..4a1a209 100644 --- a/lib/prawn-print/version.rb +++ b/lib/prawn-print/version.rb @@ -1,5 +1,5 @@ module Prawn module Print - VERSION = "0.0.3" + VERSION = "0.0.4" end end diff --git a/spec/prawn-print_spec.rb b/spec/prawn-print_spec.rb index 03e9602..b4284eb 100644 --- a/spec/prawn-print_spec.rb +++ b/spec/prawn-print_spec.rb @@ -7,18 +7,23 @@ describe Prawn::Print, "#print" do it "should work without arguments" do pdf = Prawn::Document.new - lambda { pdf.print }.should_not raise_error + expect(lambda { pdf.print }).not_to raise_error end end describe Prawn::Print, "#autoprint" do it "should work without arguments" do pdf = Prawn::Document.new - lambda { pdf.autoprint }.should_not raise_error + expect(lambda { pdf.autoprint }).not_to raise_error end it "should work with an argument" do pdf = Prawn::Document.new - lambda { pdf.autoprint("LaserJet") }.should_not raise_error + expect(lambda { pdf.autoprint("LaserJet") }).not_to raise_error + end + + it "should work with two arguments" do + pdf = Prawn::Document.new + expect(lambda { pdf.autoprint("LaserJet", true) }).not_to raise_error end end