Greetings.

I am trying to create a text string in a content byte object which has a
specific length.  Since iText does not support user supplied
font width tables I am trying to adjust the character spacing to compensate
for the difference in the measured length using the basefont and the
desired length.  The desired length is based on a printstream font which
does not exist in the pdf environment.  I tried the following code:

 // txt is an incoming text token that is being rendered in the PDF page
// c is the content byte object

BaseFont font =
BaseFont.createFont(BaseFont.HELVETICA,BaseFont.WINANSI,BaseFont.NOT_EMBEDDED);
float fs = txt.ps/10f;   // font pontsize
float x = getX(txt.x,txt.units);
float y = getY(txt.y,txt.units);
float l  = getPoints(txt.l,txt.units);  // desired length of string in
points
float r = 0;
if (txt.iDir != 0)
    r = 360-txt.iDir;
float tw = font.getWidthPoint(text,fs);  // width of string using the
basefont
c.setFontAndSize(font,fs);
c.setCharacterSpacing(l/tw);
c.beginText();
c.showTextAligned(c.ALIGN_LEFT,text,x,y,r);
c.endText();


The result is not what i hoped for . . . the resulting length of the token
in the PDF does not match the length in the printstream as I expected.

Does anyone out there know how I can solve this problem? . . . I need to
get a PDF string length to match a specific
value.

With the Adobe library it was easy because you could set the width table
for a font to match any font you like . . . however that
lib is C only and has its own set of problems.
Is there some way to accomplish this with iText . . . building zillions of
custom
fonts in a font library is not an option.  Could I subclass a font object
and provide widths? . . . Would they end up in the PDF
as a width table object associated with the font?  Other ideas?

I am open to suggestions.

Thanks in advance,
Jerold Sampson


_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to