File: inspector.rb

package info (click to toggle)
ruby-pdf-inspector 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 172 kB
  • ctags: 78
  • sloc: ruby: 282; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "pdf/reader"
require "pdf/inspector/text" 
require "pdf/inspector/xobject"
require "pdf/inspector/extgstate"
require "pdf/inspector/graphics"
require "pdf/inspector/page"
require "stringio"

module PDF
  class Inspector
    def self.analyze(output,*args,&block) 
      if output.is_a?(String)
        output = StringIO.new(output)
      end
      obs = self.new(*args, &block)
      PDF::Reader.open(output) do |reader|
        reader.pages.each do |page|
          page.walk(obs)
        end
      end
      obs  
    end         
    
    def self.analyze_file(filename,*args,&block)
      File.open(filename, "rb") do |io|
        analyze(io, *args,&block)
      end
    end  
    
    def self.parse(obj)
      PDF::Reader::Parser.new(
        PDF::Reader::Buffer.new(StringIO.new(obj)), nil).parse_token
    end
  end
end