Skip to main content
Skip table of contents

Is it possible to set a different alignment for text on the same line in the same cell?

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.

Posted on StackOverflow on Sep 15, 2015 by user2866205

If you want to separate two pieces of text in the same Paragraph, you have to use TabStops between Text entries:

public void manipulatePdf(String dest) throws Exception {
    PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
    Document doc = new Document(pdfDoc);

    Table table = new Table(1);
    Paragraph p = new Paragraph()
            .add(new Text("Left"))
            .addTabStops(new TabStop(1000, TabAlignment.RIGHT))
            .add(new Tab())
            .add(new Text("Right"));
    table.addCell(new Cell().add(p));
    doc.add(table);

    doc.close();
}

The Tab we've created separates the Strings "Left" and "Right". So the result will look like this:

Click this link if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.