Module: CommandWrap::Pdf

Defined in:
lib/command_wrap/pdf.rb

Class Method Summary collapse

Class Method Details

.merge(target, *sources) ⇒ Object

Merges the given pdfs into a single pdf



41
42
43
# File 'lib/command_wrap/pdf.rb', line 41

def self.merge (target, *sources)
    `#{CommandWrap::Config.pdftk} #{sources.join(' ')} cat output #{target}`
end

.metas(path) ⇒ Object



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

def self.metas (path)
    metas = {}

    key = ''
    `#{CommandWrap::Config.pdftk} #{path} dump_data`.gsub("\r\n", "\n").gsub("\r", "\n").split("\n").each do |line|
        parts = line.split(':')
        parts[1] = parts[1].gsub('�', '')
        if parts[0] == 'InfoValue'
            if key != ''
                metas[key] = parts[1].strip
                key = ''
            end
        elsif parts[0] == 'InfoKey'
            key = parts[1].strip
        else
            metas[parts[0].strip] = parts[1].strip
        end
    end            

    metas
end

.pages(path) ⇒ Object



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

def self.pages (path)
    metas(path)['NumberOfPages'].to_i
end

.preview(source, target, page = 0) ⇒ Object

Generates an image of a pdf page Page starts with 0



35
36
37
38
# File 'lib/command_wrap/pdf.rb', line 35

def self.preview (source, target, page = 0)
    pdf = Magick::ImageList.new(source)[page]
    pdf.write target
end