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!