pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Scheucher <andreas.scheuc...@gmail.com>
Subject Text positioning
Date Mon, 22 Dec 2014 09:46:00 GMT
Hello,

I need to read a plan exported by AutoCAD to PDF and place some markers
with text on it.
Everything works fine, except the calculation of the width of the text,
which is placed to the markers.

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 faar 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.

This is what I am doing to position the text:

                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();

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?

Thanks for your help!

regrads,
Andreas Scheucher


-- 
Andreas Scheucher e.U.
www.andreasscheucher.com, andreas.scheucher@gmail.com, +4369911196989
Dr. Robert Graf Strasse 32/10, 8010 Graz, Austria

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message