Module: Gotenberg::Chromium::Properties
- Included in:
- Gotenberg::Chromium
- Defined in:
- lib/gotenberg/chromium/properties.rb
Instance Method Summary collapse
-
#emulate_media_type(type) ⇒ Object
Forces Chromium to emulate the media type “print” or “screen”.
-
#extra_http_headers(headers) ⇒ Object
Sets extra HTTP headers that Chromium will send when loading the HTML document.
-
#fail_on_console_exceptions ⇒ Object
Forces Gotenberg to return a 409 Conflict response if there are exceptions in the Chromium console.
-
#landscape ⇒ Object
Sets the paper orientation to landscape.
-
#margins(top: nil, bottom: nil, left: nil, right: nil) ⇒ Object
Overrides the default margins (i.e., 0.39), in inches.
-
#native_page_ranges(ranges) ⇒ Object
Set the page ranges to print, e.g., “1-5, 8, 11-13”.
-
#paper_size(width, height) ⇒ Object
Overrides the default paper size, in inches.
-
#pdf_format(format) ⇒ Object
Sets the PDF format of the resulting PDF.
-
#prefer_css_page_size ⇒ Object
Forces page size as defined by CSS.
-
#print_background ⇒ Object
Prints the background graphics.
-
#scale(scale) ⇒ Object
Overrides the default scale of the page rendering (i.e., 1.0).
-
#single_page ⇒ Object
Define whether to print the entire content in one single page.
-
#url(url, extra_link_tags = [], extra_script_tags = []) ⇒ Object
Converts a target URL to PDF.
-
#user_agent(user_agent) ⇒ Object
DEPRECATED in Gotenberg 8.
-
#wait_delay(delay) ⇒ Object
Sets the duration (i.e., “1s”, “2ms”, etc.) to wait when loading an HTML document before converting it to PDF.
-
#wait_for_expression(expression) ⇒ Object
Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.
Instance Method Details
#emulate_media_type(type) ⇒ Object
Forces Chromium to emulate the media type “print” or “screen”.
113 114 115 116 117 |
# File 'lib/gotenberg/chromium/properties.rb', line 113 def emulate_media_type type properties['emulatedMediaType'] = type self end |
#extra_http_headers(headers) ⇒ Object
Sets extra HTTP headers that Chromium will send when loading the HTML document.
99 100 101 102 103 |
# File 'lib/gotenberg/chromium/properties.rb', line 99 def extra_http_headers headers properties['extraHttpHeaders'] = headers.to_json self end |
#fail_on_console_exceptions ⇒ Object
Forces Gotenberg to return a 409 Conflict response if there are exceptions in the Chromium console
106 107 108 109 110 |
# File 'lib/gotenberg/chromium/properties.rb', line 106 def fail_on_console_exceptions properties['failOnConsoleExceptions'] = true self end |
#landscape ⇒ Object
Sets the paper orientation to landscape.
56 57 58 59 60 |
# File 'lib/gotenberg/chromium/properties.rb', line 56 def landscape properties['landscape'] = true self end |
#margins(top: nil, bottom: nil, left: nil, right: nil) ⇒ Object
Overrides the default margins (i.e., 0.39), in inches.
32 33 34 35 36 37 38 39 |
# File 'lib/gotenberg/chromium/properties.rb', line 32 def margins top: nil, bottom: nil, left: nil, right: nil properties['marginTop'] = top if top properties['marginBottom'] = bottom if bottom properties['marginLeft'] = left if left properties['marginRight'] = right if right self end |
#native_page_ranges(ranges) ⇒ Object
Set the page ranges to print, e.g., “1-5, 8, 11-13”. Empty means all pages.
70 71 72 73 74 |
# File 'lib/gotenberg/chromium/properties.rb', line 70 def native_page_ranges ranges properties['nativePageRanges'] = ranges self end |
#paper_size(width, height) ⇒ Object
Overrides the default paper size, in inches. Examples of paper size (width x height): Letter - 8.5 x 11 (default) Legal - 8.5 x 14 Tabloid - 11 x 17 Ledger - 17 x 11 A0 - 33.1 x 46.8 A1 - 23.4 x 33.1 A2 - 16.54 x 23.4 A3 - 11.7 x 16.54 A4 - 8.27 x 11.7 A5 - 5.83 x 8.27 A6 - 4.13 x 5.83
24 25 26 27 28 29 |
# File 'lib/gotenberg/chromium/properties.rb', line 24 def paper_size width, height properties['paperWidth'] = width properties['paperHeight'] = height self end |
#pdf_format(format) ⇒ Object
Sets the PDF format of the resulting PDF. See gotenberg.dev/docs/modules/pdf-engines#engines.
121 122 123 124 125 |
# File 'lib/gotenberg/chromium/properties.rb', line 121 def pdf_format format properties['pdfFormat'] = format self end |
#prefer_css_page_size ⇒ Object
Forces page size as defined by CSS.
42 43 44 45 46 |
# File 'lib/gotenberg/chromium/properties.rb', line 42 def prefer_css_page_size properties['preferCssPageSize'] = true self end |
#print_background ⇒ Object
Prints the background graphics.
49 50 51 52 53 |
# File 'lib/gotenberg/chromium/properties.rb', line 49 def print_background properties['printBackground'] = true self end |
#scale(scale) ⇒ Object
Overrides the default scale of the page rendering (i.e., 1.0).
63 64 65 66 67 |
# File 'lib/gotenberg/chromium/properties.rb', line 63 def scale scale properties['scale'] = scale self end |
#single_page ⇒ Object
Define whether to print the entire content in one single page
8 9 10 |
# File 'lib/gotenberg/chromium/properties.rb', line 8 def single_page properties['singlePage'] = true end |
#url(url, extra_link_tags = [], extra_script_tags = []) ⇒ Object
Converts a target URL to PDF. See gotenberg.dev/docs/modules/chromium#url.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/gotenberg/chromium/properties.rb', line 129 def url url, = [], = [] links = .flat_map { |url| { 'href' => url } } scripts = .flat_map { |url| { 'src' => url } } properties['url'] = url properties['extraLinkTags'] = links.to_json properties['extraScriptTags'] = scripts.to_json @endpoint = '/forms/chromium/convert/url' self end |
#user_agent(user_agent) ⇒ Object
DEPRECATED in Gotenberg 8. Overrides the default “User-Agent” header.
92 93 94 95 96 |
# File 'lib/gotenberg/chromium/properties.rb', line 92 def user_agent user_agent properties['userAgent'] = user_agent self end |
#wait_delay(delay) ⇒ Object
Sets the duration (i.e., “1s”, “2ms”, etc.) to wait when loading an HTML document before converting it to PDF.
77 78 79 80 81 |
# File 'lib/gotenberg/chromium/properties.rb', line 77 def wait_delay delay properties['waitDelay'] = delay self end |
#wait_for_expression(expression) ⇒ Object
Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true. For instance: “window.status === ‘ready’”.
85 86 87 88 89 |
# File 'lib/gotenberg/chromium/properties.rb', line 85 def wait_for_expression expression properties['waitForExpression'] = expression self end |