Right alignment text in PDFBOX format?

I need to draw the text in the correct alignment using PDFBOX (java).

I am currently using ContentStream.drawString to draw text in pdf. I do not use a monospace font, so the width of the characters changes.

Any ideas?

+8
java apache pdf-generation pdfbox
source share
2 answers

A simple solution!

text_width = (myFont.getStringWidth(myString) / 1000.0f) * fontSize; contentStream.moveTextPositionByAmount(-text_width, 0); contentStream.drawString(myString); contentStream.moveTextPositionByAmount(text_width, 0); 

Where myFont = the font you are using, fontSize is the font size, and myString is the line of text you want to draw.

+16
source share

Verifiable Alignment Center Text processing code with rotated and normal PDF at http://www.javarippers.com/index.php/47/how-to-center-aligned-text-using-pdfbox-library . You can take it as a link and process your right-aligned.

-one
source share

All Articles