title: PDFQuery: get Page number where element is located
body: <p>This is the first time i use <a href="https://github.com/jcushman/pdfquery" rel="nofollow">PDFQuery</a> to scrape PDF's.</p>
  
  <p>What i need to do is to get the prices from a price list with several pages, i want to give the product code to PDFQuery, and it should find the code and return the price next to it. The problem is that using the very first example on the Github page gets the location of the text but it clearly says "Note that we don't have to know where the name is on the page, or what page it's on". Thats the case with my price list, but then all the other examples specify the page number ( <code>LTPage[pageid=1]</code> ), but i don't see where we get the page number.</p>
  
  <p>And if I don't specify the page number it returns ALL the texts in the same location for ALL the pages.</p>
  
  <p>Also, I added an <code>exactText</code> function because the codes could be, for example, "92005",  "92005C", "92005G", so using <code>:contains</code> alone doesn't help much.</p>
  
  <p>I've tried selecting the page where the element is located, and using JQuery <code>.closest</code>, both with no luck.</p>
  
  <p>I checked the <a href="http://www.unixuser.org/~euske/python/pdfminer/programming.html" rel="nofollow">PDFMiner documentation</a>  and <a href="https://pythonhosted.org/pyquery/" rel="nofollow">PyQuery documentation</a>  but i see nothing that helps me =(</p>
  
  <p>My code looks like this right now:</p>
  
  <pre><code>import pdfquery
  
  pdf = pdfquery.PDFQuery("tests/samples/priceList.pdf")
  pdf.load()
  
  code = "92005G"
  
  def exactText():
      element = str(vars(this))
      text = str("u'" + code + "\\n'")
      if text in element:
          return True
      return False
  
  #This should work if i could select the page where the element is located
  #page = pdf.pq('LTPage:contains("'+code+'")')
  #pageNum = page.attr('pageid')
  
  #Here I would replace the "8" with the page number i get, or remove the LTPage 
  #selector all together if i need to find the element first and then the page
  label = pdf.pq('LTPage[page_index="8"] LTTextLineHorizontal:contains("'+code+'")').filter(exactText)
  
  #Since we could use "JQuery selectors" i tried using ".closest", but it returns nothing
  #page = label.closest('LTPage')
  #pageNum = page.attr('pageid')
  
  left_corner = float(label.attr('x0'))
  bottom_corner = float(label.attr('y0'))
  
  #Here I would replace the "8" with the page number i get
  price = pdf.pq('LTPage[page_index="8"] LTTextLineHorizontal:in_bbox("%s, %s, %s, %s")' % (left_corner+110, bottom_corner, left_corner+140,     bottom_corner+20)).text()
  print price
  </code></pre>
  
  <p>Any help is very appreciated, guys and girls!!!</p>