Class: Texrack::PdfToPng

Inherits:
Object
  • Object
show all
Defined in:
lib/texrack/pdf_to_png.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf_path, trim, logger) ⇒ PdfToPng

Returns a new instance of PdfToPng.



6
7
8
9
10
11
12
# File 'lib/texrack/pdf_to_png.rb', line 6

def initialize(pdf_path, trim, logger)
  @pdf_path = pdf_path
  @trim     = trim
  @logger   = logger
  @line     = Cocaine::CommandLine.new(command,
    "-density 300x300 -quality 90 #{"-trim" if trim} :in :out", logger: logger)
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



4
5
6
# File 'lib/texrack/pdf_to_png.rb', line 4

def line
  @line
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/texrack/pdf_to_png.rb', line 4

def logger
  @logger
end

#pdf_pathObject (readonly)

Returns the value of attribute pdf_path.



4
5
6
# File 'lib/texrack/pdf_to_png.rb', line 4

def pdf_path
  @pdf_path
end

Instance Method Details

#commandObject



14
15
16
# File 'lib/texrack/pdf_to_png.rb', line 14

def command
  Texrack.config[:convert] || "convert"
end

#to_file(file) ⇒ Object



18
19
20
21
22
23
# File 'lib/texrack/pdf_to_png.rb', line 18

def to_file(file)
  line.run(in: pdf_path, out: file.path)
  file.path
rescue Cocaine::CommandNotFoundError => e
  raise Texrack::ConvertNotFoundError
end