Class: PDFKit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfkit/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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

def initialize
  @verbose         = false
  @use_xvfb        = false
  @meta_tag_prefix = 'pdfkit-'
  @default_options = {
    :disable_smart_shrinking => false,
    :quiet => true,
    :page_size => 'Letter',
    :margin_top => '0.75in',
    :margin_right => '0.75in',
    :margin_bottom => '0.75in',
    :margin_left => '0.75in',
    :encoding => 'UTF-8'
  }
end

Instance Attribute Details

#default_optionsObject

Returns the value of attribute default_options.



5
6
7
# File 'lib/pdfkit/configuration.rb', line 5

def default_options
  @default_options
end

#meta_tag_prefixObject

Returns the value of attribute meta_tag_prefix.



3
4
5
# File 'lib/pdfkit/configuration.rb', line 3

def meta_tag_prefix
  @meta_tag_prefix
end

#root_urlObject

Returns the value of attribute root_url.



3
4
5
# File 'lib/pdfkit/configuration.rb', line 3

def root_url
  @root_url
end

#use_xvfb=(value) ⇒ Object (writeonly)

Sets the attribute use_xvfb

Parameters:

  • value

    the value to set the attribute use_xvfb to.



4
5
6
# File 'lib/pdfkit/configuration.rb', line 4

def use_xvfb=(value)
  @use_xvfb = value
end

#verbose=(value) ⇒ Object (writeonly)

Sets the attribute verbose

Parameters:

  • value

    the value to set the attribute verbose to.



4
5
6
# File 'lib/pdfkit/configuration.rb', line 4

def verbose=(value)
  @verbose = value
end

Instance Method Details

#default_wkhtmltopdfObject



27
28
29
30
31
32
33
34
# File 'lib/pdfkit/configuration.rb', line 27

def default_wkhtmltopdf
  return @default_command_path if @default_command_path
  if defined?(Bundler::GemfileError) && File.exists?('Gemfile')
    @default_command_path = `bundle exec which wkhtmltopdf`.chomp.lines.last
  end
  @default_command_path = `which wkhtmltopdf`.chomp if @default_command_path.nil? || @default_command_path.empty?
  @default_command_path
end

#executableObject



45
46
47
# File 'lib/pdfkit/configuration.rb', line 45

def executable
  using_xvfb? ? "xvfb-run #{wkhtmltopdf}" : wkhtmltopdf
end

#quiet?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/pdfkit/configuration.rb', line 53

def quiet?
  !@verbose
end

#using_xvfb?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/pdfkit/configuration.rb', line 49

def using_xvfb?
  @use_xvfb
end

#verbose?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/pdfkit/configuration.rb', line 57

def verbose?
  @verbose
end

#wkhtmltopdfObject



23
24
25
# File 'lib/pdfkit/configuration.rb', line 23

def wkhtmltopdf
  @wkhtmltopdf ||= default_wkhtmltopdf
end

#wkhtmltopdf=(path) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/pdfkit/configuration.rb', line 36

def wkhtmltopdf=(path)
  if File.exist?(path)
    @wkhtmltopdf = path
  else
    warn "No executable found at #{path}. Will fall back to #{default_wkhtmltopdf}"
    @wkhtmltopdf = default_wkhtmltopdf
  end
end