title: How to parse pdf in Ruby
body: <p>I have been trying a simple Ruby program to parse a simple pdf file and extract the texts I am interested in. I found that <a href="https://github.com/yob/pdf-reader" rel="nofollow">pdf-reader</a> is quite good gem for pdf file parsing. I have read through the examples given in that gem and some <a href="http://pullmonkey.com/2010/01/18/ruby-pdf-reader-gem-tutorial/" rel="nofollow">tutorials</a> around that. </p>
  
  <p>I have tried the callback method and was able to get all the text from my pdf file. But I did not understand the concept behind the arguments for some of the callbacks.</p>
  
  <p>For example, If my pdf has a simple table with 3 columns and 2 rows. (Header row values are Name, Address, Age) and first row values are (Arun, Hoskote, 22) and when U run the a ruby following ruby script </p>
  
  <pre><code>receiver = PDF::Reader::RegisterReceiver.new
  reader = PDF::Reader.new("Arun.pdf")
  reader.pages.each do |page|
      page.walk(receiver)
      receiver.callbacks.each do |cb|
        puts cb.inspect
      end
  end
  </code></pre>
  
  <p>It prints series of callbacks among which some of the interesting callbacks <strong>show_text_with_positioning</strong> were like following</p>
  
  <pre><code>{:name=&gt;:show_text_with_positioning, :args=&gt;[["N", 5, "am", -4, "e"]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[[" "]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[["Ad", 6, "d", 3, "ress"]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[[" "]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[["Age"]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[[" "]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[["Ar", 4, "u", 3, "n"]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[[" "]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[["H", 3, "o", -5, "sk", 9, "o", -5,     "te"]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[[" "]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[["22"]]}
  {:name=&gt;:show_text_with_positioning, :args=&gt;[[" "]]}
  </code></pre>
  
  <p>From the above callbacks, what does args represent with respect to pdf file ? If I want to extract only name value that is 'Arun' (Anything can come here) here  or age value i,e '25' (any value can come here) here in this example, how can I do that in ruby program ? Is there any pdf-parser API or Ruby API to get only a single "interested" value(s) from a pdf file ?</p>
  
  <p>How can I write a Ruby program to access a particular callback which I am interested in which gives me the text I wanted ? </p>