Class: BookChef::Compiler::PDF

Inherits:
Object
  • Object
show all
Defined in:
lib/bookchef/compilers/pdf.rb

Overview

Converts HTML into PDF using PDFKit

Instance Method Summary collapse

Constructor Details

#initialize(html_input, options = {}) ⇒ PDF

Returns a new instance of PDF.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bookchef/compilers/pdf.rb', line 10

def initialize(html_input, options = {})
  
  @html_input = html_input
  default_options = {
    output_file:        "/tmp/output.pdf",
    footer_html_file:   "#{BookChef::LIB_PATH}/templates/footer.html",
    footer_custom_html: ""
  }
  @options = default_options.merge(options)

  create_footer

  @pdf = PDFKit.new(
    @html_input,
    enable_external_links: true,
    enable_internal_links: true,
    footer_html: @options[:temp_footer_filename]
  )

end

Instance Method Details

#compileObject



31
32
33
34
# File 'lib/bookchef/compilers/pdf.rb', line 31

def compile
  @pdf.to_file(@options[:output_file])
  after_compile
end