title: Extract all text with string positions from a PDF
body: <p>This may seem an old question, but I didn't find an exhaustive answer after spending half an hour searching all over SO.</p>
  
  <p>I am using PDFBox and I would like to extract all of the text from a PDF file along with the coordinates of each string. I am using their <code>PrintTextLocations</code> example (<a href="http://pdfbox.apache.org/apidocs/org/apache/pdfbox/examples/util/PrintTextLocations.html" rel="nofollow">http://pdfbox.apache.org/apidocs/org/apache/pdfbox/examples/util/PrintTextLocations.html</a>) but with the kind of pdf I am using (E-Tickets) the program fails to recognize strings, printing each character separately. The output is a list of strings (each representing a <code>TextPosition</code> object) like this:</p>
  
  <pre><code>String[414.93896,637.2442 fs=1.0 xscale=8.0 height=4.94 space=2.2240002 width=4.0] s
  String[418.93896,637.2442 fs=1.0 xscale=8.0 height=4.94 space=2.2240002 width=4.447998] a
  String[423.38696,637.2442 fs=1.0 xscale=8.0 height=4.94 space=2.2240002 width=1.776001] l
  String[425.16296,637.2442 fs=1.0 xscale=8.0 height=4.94 space=2.2240002 width=4.447998] e
  </code></pre>
  
  <p>While I would like the program to recognize the string "sale" as an unique <code>TextPosition</code> and give me its position.
  I also tried to play with the <code>setSpacingTolerance()</code> and <code>setAverageCharacterTolerance()</code> <code>PDFTextStripper</code> methods, setting different values above and under the standard values (which FYI are 0.5 and 0.3 respectively), but the output didn't change at all. Where am I going wrong? Thanks in advance.</p>