Module: PDF::Toolkit::Native

Included in:
PDF::Toolkit
Defined in:
lib/pdf/toolkit/native.rb

Instance Method Summary collapse

Instance Method Details

#pdftk(*args, &block) ⇒ Object

Invoke pdftk with the given arguments, plus dont_ask. If :mode or a block is given, IO::popen is called. Otherwise, Kernel#system is used.

result = PDF::Toolkit.pdftk(*%w(foo.pdf bar.pdf cat output baz.pdf))
io = PDF::Toolkit.pdftk("foo.pdf","dump_data","output","-",:mode => 'r')
PDF::Toolkit.pdftk("foo.pdf","dump_data","output","-") { |io| io.read }


11
12
13
14
15
16
17
# File 'lib/pdf/toolkit/native.rb', line 11

def pdftk(*args,&block)
  options = args.last.is_a?(Hash) ? args.pop : {}
  args << "dont_ask"
  args << options
  result = call_program("pdftk",*args,&block)
  return block_given? ? $?.success? : result
end

#pdftotext(file, outfile = nil, &block) ⇒ Object

Invoke pdftotext. If outfile is omitted, returns an IO object for the output.



21
22
23
24
# File 'lib/pdf/toolkit/native.rb', line 21

def pdftotext(file,outfile = nil,&block)
  call_program("pdftotext",file,
    outfile||"-",:mode => (outfile ? nil : 'r'),&block)
end