Hi I have a following problem,

I am using the PDFStamper object to place a variable length string in the PDF file. The problem is that if the string is too long, it goes off the screen. The problem is that the font of the string and the length are also variant...

I have googled and found solutions to find the length of the String in Java, using FontMetrics class:

    protected int GetWidth(Font font, String text)
    {
        FontMetrics fontMetrics = getFontMetrics(font);
       
        return fontMetrics.stringWidth(text);;
    }

with the width of the text I can calculate the placement of the text (based on page size) as well as manipulate the font size....

BUT

it seems that the GetWidth function returns only an approximation of the string length in pixels, and the string will still sometimes go off the screen (i am only subtracting the size returned by GetWidth from the width of the page).

Is there any way to fix the above problem using iText classes?? (measure the string in pixels, or fit text on a field that can be later stamped in the document)

Thanks a lot in advance,

regards,

cierech

Reply via email to