class Postdoc::Client
Attributes
client[RW]
Public Class Methods
new(port)
click to toggle source
# File lib/postdoc/client.rb, line 10 def initialize(port) @port = port 100.times { setup_connection_or_wait && break } raise 'ChromeClient couldn\'t launch' if @client.blank? end
Public Instance Methods
print_document(file_path, settings: PrintSettings.new)
click to toggle source
# File lib/postdoc/client.rb, line 30 def print_document(file_path, settings: PrintSettings.new) client.send_cmd 'Page.enable' client.send_cmd 'Page.navigate', url: "file://#{file_path}" client.wait_for 'Page.loadEventFired' response = client.send_cmd 'Page.printToPDF', settings.to_cmd Base64.decode64 response['data'] end
print_pdf_from_html(file_path, settings: PrintSettings.new)
click to toggle source
We should move away from passing options like this and collect them in the prinbt settings.
# File lib/postdoc/client.rb, line 18 def print_pdf_from_html(file_path, settings: PrintSettings.new) client.send_cmd 'Page.enable' client.send_cmd 'Page.navigate', url: "file://#{file_path}" client.wait_for 'Page.loadEventFired' response = client.send_cmd 'Page.printToPDF', settings.to_cmd Base64.decode64 response['data'] end
Private Instance Methods
setup_connection_or_wait()
click to toggle source
# File lib/postdoc/client.rb, line 41 def setup_connection_or_wait @client = ChromeRemote.client(port: @port) true rescue sleep(0.1) false end