I'm creating a TOC example and I have that part done. Here's the code:
public static void textLine(PdfContentByte cb, float y, float left,
float right, String connect, Font fontConnect, Phrase phraseLeft, Phrase
phraseRight, PdfAction link) {
float phraseLeftWidth = ColumnText.getWidth(phraseLeft);
float phraseRightWidth = ColumnText.getWidth(phraseRight);
float widthRemaining = right - left - phraseRightWidth -
phraseLeftWidth;
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, phraseLeft,
left, y, 0);
if (connect != null) {
float cw = ColumnText.getWidth(new Phrase(connect,
fontConnect));
int rep = (int)(widthRemaining / cw);
if (rep > 0) {
StringBuffer sb = new StringBuffer();
for (int k = 0; k < rep; ++k)
sb.append(connect);
ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, new
Phrase(sb.toString(), fontConnect), right - phraseRightWidth, y, 0);
}
}
ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, phraseRight,
right, y, 0);
if (link != null)
cb.setAction(link, left, y, right, y + 12);
}
The connect and fontConnect are the dots or whatever you want.
Best Regards,
Paulo Soares
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of [EMAIL PROTECTED]
> Sent: Tuesday, June 22, 2004 10:20 AM
> To: [EMAIL PROTECTED]
> Subject: [iText-questions] String widths in iText
>
> Hi All,
>
> I'm a newbie to iText, and I am trying to create an index page
> similar to the following:
>
> First topic .......... 1
> 2nd top .............. 2
> No.3 ................. 3
>
> The alignment of text is easy enough, but to generate the correct
> number of 'dots' between an entry and its page number, I need to find
> the width of the two strings (in pixels). And there lies my problem -
> I don't know how to do this in iText.
>
> Has anyone got any ideas? Any help would be greatly appreciated...
>
> Thanks!
>
>
> - Terry
>
>
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions