Class: Postdoc::Client
- Inherits:
-
Object
- Object
- Postdoc::Client
- Defined in:
- lib/postdoc/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(port) ⇒ Client
constructor
A new instance of Client.
- #print_pdf_from_html(file_path, header_template: false, footer_template: false, **options) ⇒ Object
Constructor Details
#initialize(port) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/postdoc/client.rb', line 9 def initialize(port) @port = port 100.times { setup_connection_or_wait && break } raise 'ChromeClient couldn\'t launch' if @client.blank? end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/postdoc/client.rb', line 7 def client @client end |
Instance Method Details
#print_pdf_from_html(file_path, header_template: false, footer_template: false, **options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/postdoc/client.rb', line 15 def print_pdf_from_html(file_path, header_template: false, footer_template: false, **) 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', { landscape: [:landscape] || false, printBackground: true, marginTop: [:margin_top] || 1, marginBottom: [:margin_bottom] || 1, marginLeft: [:margin_left] || 1, marginRight: [:margin_right] || 1, displayHeaderFooter: !!(header_template || ), headerTemplate: header_template || '', footerTemplate: || '' } Base64.decode64 response['data'] end |