Text position issue

Hi,

We are stamping text to existing PDF document, but I ran into a
strange issue when I was testing the application. Here are the specs:
1 - Text to be stamped is variable
2 - Text position is set by the user (inches)

It looks like the text position I set via cmd line is not the one I
wanted. Take a look at a piece of my code:

            writer.begin( page );
            pdftron.PDF.Element element =
builder.createTextBegin( Font.create( pdfDoc, font ), fontSize );
            writer.writeElement( element );
            element = builder.createTextRun( whiteIndex );
            // get the real text position
            double x = xPosition * 72;
            double y = page.getPageHeight() - ( yPosition * 72 );
            System.out.println( category, "x: " + x );
            CommonLog.getLog().write( category, "y: " + y );
            // set the text position
            element.setTextMatrix( 1, 0, 0, 1, x, y );
            Rect rect = element.getBBox();
            System.out.println( category, "X1: " + rect.getX1() );
            System.out.println( category, "Y1: " + rect.getY1() );
            System.out.println( category, "X2: " + rect.getX2() );
            System.out.println( category, "Y2: " + rect.getY2() );
            // set text color to white
            GState gstate = element.getGState();
            gstate.setFillColorSpace( ColorSpace.createDeviceRGB() );
            gstate.setFillColor( new ColorPt( 0, 0, 1 ) );
            writer.writeElement( element );
            writer.writeElement( builder.createTextEnd() );
            writer.end();

Not sure why, but the Rect object from the text Element does not have
the coordinates I set using the setTextMatrix() method. Am I missing
something?
Thanks!

You would need to take into account the page rotation or crop-box
offset.
Probably the simplest way is to use page.GetDefaultMatrix() as
described in the following articles:

What is the proper way to add new content to an existing (rotated/
cropped) PDF page:
http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/10190611076bd2cd/eb7382f49c0ee0fe

Taking into account effect of page rotation when adding new content to
a page:
http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/5c584dc46a707c37/8ff9b9474d1bbdce

Since you are adding fairly simple stamp you may also want to consider
using 'pdftron.PDF.Stamper' (http://www.pdftron.com/pdfnet/
samplecode.html#Stamper) which is much simpler to use.