1

In one cell and on the same line, I must add two text (name and date). The first snippet of text must be on the left page side, the second one on the right, and everything must be in one line. I've tried used Paragraphs, Chunks and Phrases but I don't know how to do it.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
user2866205
  • 61
  • 1
  • 7

2 Answers2

3

If you want to separate two pieces of text in the same Phrase or Paragraph, you have to create a Chunk I often refer to as glue:

Chunk glue = new Chunk(new VerticalPositionMark());

You can use this glue like this:

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    Chunk glue = new Chunk(new VerticalPositionMark());
    PdfPTable table = new PdfPTable(1);
    Phrase p = new Phrase();
    p.add("Left");
    p.add(glue);
    p.add("Right");
    table.addCell(p);
    document.add(table);
    document.close();
}

The result looks like this:

enter image description here

As you can see, the special Chunk we've created separates the Strings "left" and "right".

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
0

Just use two paragraphs, chunks or phrases. If you are trying to do it with just one of the three, you are limited. Just define another text field to be added to the page. You can use any combination of three, and set the location on the page to reflect your requirements.

Todd
  • 223
  • 3
  • 13