About us | News | Contact
iText ® Licenses Support   
You are here: Home > Forums > iText in Action — Second Edition > Part 1: Creating PDF documents from scratch > Chapter 5: Table, cell, and page events
User login
  • Request new password

Footers - Multiple lines?

Submitted by notace on Mon, 07/18/2011 - 03:55

Is it possible to add multi-line footers to a document, using the techniques described in Chapter 5? I have the following code:

Date today = new Date();
Format formatter = new SimpleDateFormat("dd MMM yyyy");

Phrase footer = new Phrase(new Chunk("PRICES ARE EX MELBOURNE / PERTH / BRISBANE WAREHOUSE\n", BOLD10));

footer.setLeading(12);
footer.add(new Chunk("There is no obligation to comply with these prices. Date Printed: " + formatter.format(today), NORM10));
ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
footer, (rect.getLeft() + rect.getRight()) / 2,
rect.getBottom()+72, 0);

But this only outputs the first line ("PRICES ARE EX ..."). Is there a special trick to having multi-line footers? Am I missing something blindingly simple?

Thanks, Ron

‹ Template not rendering as expected Adding Headers and Footers ›
  • Login to post comments

Use ColumnText in a different way

Submitted by Bruno Lowagie on Mon, 07/18/2011 - 06:59.

Yes, it's possible to have multiline footers, but you're using the wrong approach.
You're using the static ColumnText.showTextAligned() method. As explained on p77: It would be nice if you could add the text to rectangles without having to scale the text or downsize the font size if the title is too long to fit the width of the rectangle. This can't be done with the showTextAligned() method, to which you only pass a single set of (x,y) coordinates; you need an instance of the ColumnText object instead.
This snippet of text precedes section 3.3, entitled "Working with the ColumnText object." Your question is answered in that section.

  • Login to post comments
Content © 2010 1T3XT BVBA