views:

690

answers:

1

Hi. Does anyone know, how to, in iText, add multiline text in bounding box (with coordinates specified).

I tried

 cb.showTextAligned(PdfContentByte.ALIGN_LEFT, text, bounds.getLeft(), TOTAL_HEIGHT-bounds.getTop(), 0);

But it does not support newlines. I also tried

  PdfContentByte cb = writer.getDirectContent();
  cb.moveText(300,400);
  document.add(new Paragraph("TEST paragraph\nNewline"));

This supports newlines but does not react to moveText, so I don't know how to put it at given position or better: bounding box.

I suspect chunks or PdfTemplate or maybe table might help, but i don't (yet) know how to put it together. TIA for help.

+1  A: 

Try this:

ColumnText ct = new ColumnText(cb);
Phrase myText = new Phrase("TEST paragraph\nNewline");
ct.SetSimpleColumn(myText, 34, 750, 580, 317, 15, Element.ALIGN_LEFT);
ct.Go();

parameters of SetSimpleColumn are:

  1. the phrase
  2. leftmargin coordinate
  3. bottommargin coordinate
  4. box width
  5. box height
  6. line height
  7. alignment.
Yannick Smits
Thanks. I actually wrote a mini-library for layouts and auto-fitting and tables, which incorporates things you have written in your response.
karolrvn