How do I set paragraph indentation in iText?

To set paragraph indentation in the iText Paragraph object we can use the setFirstLineIndent(), setIndentationLeft() and setIndentationRight(). These methods accept a float value as a parameter.

The setFirstLineIndent() method set the first line indentation of a paragraph, while the setIndentationLeft() and setIndentationRight() methods set the left and the right indent of the paragraph. Let see an example below:

package org.kodejava.example.itextpdf;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;


public class ParagraphIndentationDemo {
    private static final String CONTENT =
            "Lorem ipsum dolor sit amet, consectetur adipisicing " +
                    "elit, sed do eiusmod tempor incididunt ut labore et " +
                    "dolore magna aliqua. Ut enim ad minim veniam, quis " +
                    "nostrud exercitation ullamco laboris nisi ut aliquip " +
                    "ex ea commodo consequat. Duis aute irure dolor in " +
                    "reprehenderit in voluptate velit esse cillum dolore eu " +
                    "fugiat nulla pariatur. Excepteur sint occaecat cupidatat " +
                    "non proident, sunt in culpa qui officia deserunt mollit " +
                    "anim id est laborum.";

    public static void main(String[] args) {
        Document document = new Document();
        try {
                    new FileOutputStream("ParaIndentation.pdf"));

            Paragraph paragraph = new Paragraph();
            paragraph.add(new Chunk(ParagraphIndentationDemo.CONTENT));

            // Set paragraph's first line indent

            // Set paragraph's left side indent

            // Set paragraph's right side indent
        } catch (DocumentException | FileNotFoundException e) {
        } finally {

Maven Dependencies

Wayan Saryada

Wayan Saryada

A programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, JPA, etc. If you need help on Java programming you can hire me on Fiverr.
Wayan Saryada

Leave a Reply