Module: Gotenberg::Chromium::Files

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

Instance Method Summary collapse

Instance Method Details

#assets(sources) ⇒ Object



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

def assets sources
  sources.each do |f|
    files << multipart_file(IO.binread(f), File.basename(f))
  end

  self
end

#binary_assets(sources) ⇒ Object

Sets the additional files, like images, fonts, stylesheets, and so on.



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

def binary_assets sources
  sources.each do |(io, filename)|
    files << multipart_file(io, filename)
  end

  self
end

#filesObject



73
74
75
# File 'lib/gotenberg/chromium/files.rb', line 73

def files
  @files ||= []
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
# File 'lib/gotenberg/chromium/files.rb', line 18

def footer footer
  compiler = Compiler.new(footer)

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

#header(header) ⇒ Object

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



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

def header header
  compiler = Compiler.new(header)

  files << multipart_file(compiler.body, 'header.html', 'text/html')
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.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gotenberg/chromium/files.rb', line 27

def html index
  compiler = Compiler.new(index)

  meta((compiler.body))

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

  binary_assets(compiler.assets)

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

  self
end

#markdown(index, markdowns = []) ⇒ 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.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gotenberg/chromium/files.rb', line 44

def markdown index, markdowns = []
  files << multipart_file(index, 'index.html', 'text/html')

  markdowns.each do |f|
    files << multipart_file(IO.binread(f), File.basename(f), 'text/markdown')
  end
  
  @endpoint = '/forms/chromium/convert/markdown'

  self
end