Class: Bidi2pdf::Bidi::Commands::PagePrint
- Inherits:
-
Object
- Object
- Bidi2pdf::Bidi::Commands::PagePrint
- Includes:
- Base
- Defined in:
- lib/bidi2pdf/bidi/commands/page_print.rb
Instance Method Summary collapse
-
#initialize(cdp_session:, print_options:) ⇒ PagePrint
constructor
A new instance of PagePrint.
-
#method_name ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#params ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
Methods included from Base
#==, #as_payload, #eql?, #hash, #inspect
Constructor Details
#initialize(cdp_session:, print_options:) ⇒ PagePrint
Returns a new instance of PagePrint.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bidi2pdf/bidi/commands/page_print.rb', line 11 def initialize(cdp_session:, print_options:) @cdp_session = cdp_session = || { background: true } PrintParametersValidator.validate!() return unless [:page]&.key?(:format) [:page] = Bidi2pdf.translate_paper_format [:page][:format] end |
Instance Method Details
#method_name ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
58 59 60 |
# File 'lib/bidi2pdf/bidi/commands/page_print.rb', line 58 def method_name "goog:cdp.sendCommand" end |
#params ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
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 |
# File 'lib/bidi2pdf/bidi/commands/page_print.rb', line 23 def params { # https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF method: "Page.printToPDF", session: @cdp_session, params: { "printBackground" => [:background], "marginTop" => cm_to_inch(.dig(:margin, :top) || 0), "marginBottom" => cm_to_inch(.dig(:margin, :bottom) || 0), "marginLeft" => cm_to_inch(.dig(:margin, :left) || 0), "marginRight" => cm_to_inch(.dig(:margin, :right) || 0), "landscape" => ([:orientation] || "portrait").to_sym == :landscape, "paperWidth" => cm_to_inch(.dig(:page, :width)), "paperHeight" => cm_to_inch(.dig(:page, :height)), "pageRanges" => page_ranges_to_string([:pageRanges]), "scale" => [:scale] || 1.0, "displayHeaderFooter" => [:display_header_footer], "headerTemplate" => [:header_template] || "", "footerTemplate" => [:footer_template] || "", "preferCSSPageSize" => .fetch(:prefer_css_page_size, true), "generateTaggedPDF" => .fetch(:generate_tagged_pdf, false), "generateDocumentOutline" => .fetch(:generate_document_outline, false), transferMode: "ReturnAsBase64" }.compact } end |