title: Calculate correct width of a text
body: <p>I need to read a plan exported by AutoCAD to PDF and place some markers with text on it with PDFBox. 
  Everything works fine, except the calculation of the width of the text, which is written next to the markers.</p>
  
  <p>I skimmed through the whole PDF specification and read in detail the parts, which deal with the graphic and the text, but to no avail. As far as I understand, the glyph coordinate space is set up in a 1/1000 of the user coordinate space. Hence the width need to be scale up by 1000, but it's still a fraction of the real width.</p>
  
  <p>This is what I am doing to position the text:</p>
  
  <pre><code>float textWidth = font.getStringWidth(marker.id) * 0.043f;
  contentStream.beginText();
  contentStream.setTextScaling(1, 1, 0, 0);
  contentStream.moveTextPositionByAmount(
    marker.endX + marker.getXTextOffset(textWidth, fontPadding),
    marker.endY + marker.getYTextOffset(fontSize, fontPadding));
  contentStream.drawString(marker.id);
  contentStream.endText();
  </code></pre>
  
  <p>The * 0.043f works as an approximation for one document, but fails for the next.
  Do I need to reset any other transformation matrix except the text matrix?</p>
  
  <p>EDIT: A full idea example project is on github with tests and example pdfs: <a href="https://github.com/ascheucher/pdf-stamp-prototype" rel="nofollow noreferrer">https://github.com/ascheucher/pdf-stamp-prototype</a></p>
  
  <p>Thanks for your help!</p>