Hi Gerrit,

which version of PDFBox are you using? Could you post a small code snippet to 
reproduce the issue? With a quick test I created  the numbers do print fine 
i.e. they have the same width.

Her my code:

        PDDocument doc = new PDDocument();

        PDPage page = new PDPage();
        doc.addPage( page );
        PDFont font = PDType1Font.HELVETICA;

        PDPageContentStream contentStream = new PDPageContentStream(doc, page);
        contentStream.beginText();
        contentStream.setFont( font, 12 );
        contentStream.moveTextPositionByAmount( 100, 700 );
        contentStream.drawString( "1111 " + font.getStringWidth("1111"));
        contentStream.moveTextPositionByAmount( 0, 20 );
        contentStream.drawString( "2222 " + font.getStringWidth("2222"));
        contentStream.moveTextPositionByAmount( 0, 20 );
        contentStream.drawString( "12 " + font.getStringWidth("12"));
        contentStream.moveTextPositionByAmount( 0, 20 );
        contentStream.drawString( "32 " + font.getStringWidth("32"));
        contentStream.endText();
        contentStream.close();
        doc.save( "test.pdf" );


Kind regards

Maruan Sahyoun


Am 05.12.2012 um 14:49 schrieb Gerrit Lober <gerritlo...@gmx.de>:

> Dear all,
> 
> I've the following problem with PDFbox. I try to paint a rectangle with 
> PDPageContentStream and then put a figure in the center of this rectangle.
> 
> Therefore I try to calculate the width of the text. The Method getStringWidth 
> returns everytime the same width for all figures. That means that I get the 
> same result for "12" and "32". Because the "1" is smaller than the "3" 
> something is not correct and my "12" is a bit to right.
> 
> What is the reason for this?
> 
> I get the Font with the following code:
> private PDFont getFont() throws IOException {
>  return PDType1Font.HELVETICA;
> }
> 
> Thanks!
> 

Reply via email to