Module: Gotenberg::Chromium::Properties

Included in:
Gotenberg::Chromium
Defined in:
lib/gotenberg/chromium/properties.rb

Instance Method Summary collapse

Instance Method Details

#emulate_media_type(type) ⇒ Object

Forces Chromium to emulate the media type “print” or “screen”.



108
109
110
111
112
# File 'lib/gotenberg/chromium/properties.rb', line 108

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.



94
95
96
97
98
# File 'lib/gotenberg/chromium/properties.rb', line 94

def extra_http_headers headers
  properties['userAgent'] = headers.to_json

  self
end

#fail_on_console_exceptionsObject

Forces Gotenberg to return a 409 Conflict response if there are exceptions in the Chromium console



101
102
103
104
105
# File 'lib/gotenberg/chromium/properties.rb', line 101

def fail_on_console_exceptions
  properties['failOnConsoleExceptions'] = true

  self
end

#landscapeObject

Sets the paper orientation to landscape.



51
52
53
54
55
# File 'lib/gotenberg/chromium/properties.rb', line 51

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.



27
28
29
30
31
32
33
34
# File 'lib/gotenberg/chromium/properties.rb', line 27

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.



65
66
67
68
69
# File 'lib/gotenberg/chromium/properties.rb', line 65

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



19
20
21
22
23
24
# File 'lib/gotenberg/chromium/properties.rb', line 19

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.



116
117
118
119
120
# File 'lib/gotenberg/chromium/properties.rb', line 116

def pdf_format format
  properties['pdfFormat'] = format

  self
end

#prefer_css_page_sizeObject

Forces page size as defined by CSS.



37
38
39
40
41
# File 'lib/gotenberg/chromium/properties.rb', line 37

def prefer_css_page_size
  properties['preferCssPageSize'] = true

  self
end

Prints the background graphics.



44
45
46
47
48
# File 'lib/gotenberg/chromium/properties.rb', line 44

def print_background
  properties['printBackground'] = true

  self
end

#scale(scale) ⇒ Object

Overrides the default scale of the page rendering (i.e., 1.0).



58
59
60
61
62
# File 'lib/gotenberg/chromium/properties.rb', line 58

def scale scale
  properties['scale'] = scale

  self
end

#url(url, extra_link_tags = [], extra_script_tags = []) ⇒ Object

Converts a target URL to PDF. See gotenberg.dev/docs/modules/chromium#url.



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gotenberg/chromium/properties.rb', line 124

def url url, extra_link_tags = [], extra_script_tags = []
  links = extra_link_tags.flat_map { |url| { 'href' => url } }
  scripts = extra_script_tags.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

Overrides the default “User-Agent” header.



87
88
89
90
91
# File 'lib/gotenberg/chromium/properties.rb', line 87

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.



72
73
74
75
76
# File 'lib/gotenberg/chromium/properties.rb', line 72

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’”.



80
81
82
83
84
# File 'lib/gotenberg/chromium/properties.rb', line 80

def wait_for_expression expression
  properties['waitForExpression'] = expression

  self
end