Module: Gotenberg::Chromium::Tools

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

Instance Method Summary collapse

Instance Method Details

#assets(*sources) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/gotenberg/chromium/tools.rb', line 55

def assets *sources
  sources.each do |source|
    files << multipart_file(*load_file_from_source(source))
  end

  self
end

Adds a footer to each page. Note: it automatically sets the filename to “footer.html”, as required by Gotenberg.



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

def footer footer
  compiler = Compiler.new(footer)

  files << multipart_file(compiler.body, 'footer.html', 'text/html')

  self
end

#header(header) ⇒ Object

Adds a header to each page. Note: it automatically sets the filename to “header.html”, as required by Gotenberg.



8
9
10
11
12
13
14
# File 'lib/gotenberg/chromium/tools.rb', line 8

def header header
  compiler = Compiler.new(header)

  files << multipart_file(compiler.body, 'header.html', 'text/html')

  self
end

#html(index) ⇒ Object

Converts an HTML document to PDF. Note: it automatically sets the index filename to “index.html”, as required by Gotenberg. See gotenberg.dev/docs/modules/chromium#html.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gotenberg/chromium/tools.rb', line 29

def html index
  compiler = Compiler.new(index)

  meta((compiler.body))

  files << multipart_file(compiler.body, 'index.html', 'text/html')

  assets *compiler.assets

  @endpoint = '/forms/chromium/convert/html'

  self
end

#markdown(index, markdown) ⇒ Object

Converts one or more markdown files to PDF. Note: it automatically sets the index filename to “index.html”, as required by Gotenberg. See gotenberg.dev/docs/modules/chromium#markdown.



46
47
48
49
50
51
52
53
# File 'lib/gotenberg/chromium/tools.rb', line 46

def markdown index, markdown
  files << multipart_file(index, 'index.html', 'text/html')
  files << multipart_file(*load_file_from_source(markdown), 'text/markdown')

  @endpoint = '/forms/chromium/convert/markdown'

  self
end