Module: Pdfunite

Defined in:
lib/pdfunite.rb,
lib/pdfunite/version.rb

Defined Under Namespace

Classes: BinaryNotFound

Constant Summary collapse

VERSION =
'0.6.0'
@@logger =
nil
@@binary =
'pdfunite'

Class Method Summary collapse

Class Method Details

.binaryObject



32
33
34
# File 'lib/pdfunite.rb', line 32

def binary
  @@binary
end

.binary=(binary) ⇒ Object

You can set a custom pdfunite binary here



28
29
30
# File 'lib/pdfunite.rb', line 28

def binary=(binary)
  @@binary = binary
end

.join(*args) ⇒ Object

Join PDF files or PDF data

Pdfunite.join(filenames) Pdfunite.join(objects) { |obj| obj.to_pdf }



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pdfunite.rb', line 42

def join(*args)
  output = nil
  Dir.mktmpdir do |dir|
    tmpdir = Pathname.new(dir).realpath
    files = args.flatten(1).collect.with_index do |arg, idx|
      realpath = if block_given?
        data = yield(arg)
        file = tmpdir.join("#{idx}.pdf")
        file.open('wb') { |f| f << data }
        file.realpath
      else
        Pathname.new(arg).realpath
      end
      realpath.to_s
    end
    outfile = tmpdir.join('output.pdf')
    cmdline = [binary.to_s, *files, outfile.to_s]
    output = outfile.binread if run_command(cmdline.shelljoin)
  end
  output
end

.loggerObject



21
22
23
# File 'lib/pdfunite.rb', line 21

def logger
  @@logger
end

.logger=(logger) ⇒ Object

You can set a custom logger here



17
18
19
# File 'lib/pdfunite.rb', line 17

def logger=(logger)
  @@logger = logger
end