Class: Palapala::PDF

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

Overview

Page class to generate PDF from HTML content using Chrome in headless mode in a thread-safe way

Instance Method Summary collapse

Constructor Details

#initialize(content = nil, header_html: nil, footer_html: nil, generate_tagged_pdf: Palapala.defaults.fetch(:generate_tagged_pdf, false), prefer_css_page_size: Palapala.defaults.fetch(:prefer_css_page_size, true), scale: Palapala.defaults.fetch(:scale, 1), page_ranges: Palapala.defaults.fetch(:page_ranges, nil), margin: Palapala.defaults.fetch(:margin, {})) ⇒ PDF

Returns a new instance of PDF.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/palapala/pdf.rb', line 7

def initialize(content = nil,
               header_html: nil,
               footer_html: nil,
               generate_tagged_pdf: Palapala.defaults.fetch(:generate_tagged_pdf, false),
               prefer_css_page_size: Palapala.defaults.fetch(:prefer_css_page_size, true),
               scale: Palapala.defaults.fetch(:scale, 1),
               page_ranges: Palapala.defaults.fetch(:page_ranges, nil),
               margin: Palapala.defaults.fetch(:margin, {}))
  @content = content
  @header_html = header_html
  @footer_html = footer_html
  @generate_tagged_pdf = generate_tagged_pdf
  @prefer_css_page_size = prefer_css_page_size
  @page_ranges = page_ranges
  @scale = scale
  @margin = margin
end

Instance Method Details

#binary_data(**opts) ⇒ Object



25
26
27
# File 'lib/palapala/pdf.rb', line 25

def binary_data(**opts)
  pdf(**opts)
end

#save(path, **opts) ⇒ Object



29
30
31
# File 'lib/palapala/pdf.rb', line 29

def save(path, **opts)
  File.binwrite(path, pdf(**opts))
end