stupidStudent
stupidStudent

Reputation: 11

Itext - How to underline half line?

I am creating a PDF using iText. I want to underline half text of paragraph up to the end of line includingу empty space.

How can I achieve this?

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    Phrase phrase = new Phrase("Help me ");
    Paragraph p = new Paragraph();
    p.add(phrase);
    Phrase phrase1 = new Phrase("pls");
    LineSeparator ls = new LineSeparator();
    ls.setOffset(-2);
    phrase1.add(ls);
    p.add(phrase1);
    document.add(p);
    document.close();
}

Upvotes: 1

Views: 1161

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

You have an ls instance created like this:

LineSeparator ls = new LineSeparator();

You want the line to span half of the available width. That can be done with the setPercentage() method:

ls.setPercentage(50);

Upvotes: 1

Related Questions