SHARE
TWEET

Untitled

a guest Dec 3rd, 2011 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env ruby
  2.  
  3. require 'poppler'
  4.  
  5. class PDFParser
  6.   def initialize(params = nil)
  7.     @loaded = false
  8.     if (params != nil) then
  9.       @file = params[:file] || nil
  10.       if (@file != nil) then
  11.         loadFile(@file)
  12.       end
  13.     else
  14.       @file = nil
  15.     end
  16.   end
  17.  
  18.   def loadFile(fileName)
  19.     @loaded = false
  20.     if (!File.exists?(fileName)) then
  21.       raise 'file not found ' + fileName
  22.     end
  23.     @file = fileName
  24.     @poppler = Poppler::Document.new(@file)
  25.     pageCount = 0;
  26.     @poppler.each do |page|
  27.       pageCount+=1
  28.     end
  29.     @pageCount = pageCount
  30.     @loaded = true
  31.   end
  32.  
  33.   def DumpLinks
  34.     if (!@loaded) then
  35.       loadFile(@file)
  36.     end
  37.     @poppler.each do |page|
  38.       links = page.link_mapping
  39.       links.each do |link|
  40.         action = link.action
  41.         if(action.is_a?(Poppler::ActionGotoDest))
  42.           puts "Destination: page_num: %d, top: %f, left: %f, right: %f, zoom: %f, dest: %s" %
  43.             [action.dest.page_num, action.dest.top, action.dest.left, action.dest.right, action.dest.zoom, action.dest.named_dest]
  44.           namedDest = action.dest.named_dest
  45.           puts namedDest
  46.           if (namedDest != nil) then
  47.             dest = @poppler.find_dest(namedDest)
  48.             puts dest
  49.           end
  50.         end
  51.       end
  52.     end
  53.   end
  54. end
  55.  
  56.  
RAW Paste Data
Want to get better at Ruby?
Learn to code Ruby in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top