iText pdf library
Website search

Alignment, indentation, leading and spacing in cells

CenteredTextInCell.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2019 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/**
 * Example written by Bruno Lowagie in answer to:
 * http://stackoverflow.com/questions/19703715/centered-text-in-itext-pdf-table-cell
 */
package com.itextpdf.samples.sandbox.tables;
 
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.io.font.FontProgramFactory;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.property.VerticalAlignment;
 
import java.io.File;
 
public class CenteredTextInCell {
    public static final String DEST = "./target/sandbox/tables/centered_text_in_cell.pdf";
 
    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new CenteredTextInCell().manipulatePdf(DEST);
    }
 
    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
        PdfFont font = PdfFontFactory.createFont(FontProgramFactory.createFont(StandardFonts.HELVETICA_BOLD));
        Paragraph para = new Paragraph("Test").setFont(font);
        para.setFixedLeading(0);
        para.setMultipliedLeading(1);
        Table table = new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth();
        Cell cell = new Cell();
        cell.setMinHeight(50);
        cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
        cell.add(para);
        table.addCell(cell);
        doc.add(table);
 
        doc.close();
    }
}
IndentTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2019 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
package com.itextpdf.samples.sandbox.tables;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.UnitValue;
 
import java.io.File;
 
public class IndentTable {
    public static final String DEST = "./target/sandbox/tables/indent_table.pdf";
 
    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new IndentTable().manipulatePdf(DEST);
    }
 
    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
 
        PdfCanvas cb = new PdfCanvas(pdfDoc.addNewPage());
        cb.moveTo(36, 842);
        cb.lineTo(36, 0);
        cb.stroke();
        Table table = new Table(UnitValue.createPercentArray(8)).useAllAvailableWidth();
        table.setHorizontalAlignment(HorizontalAlignment.LEFT);
        table.setWidth(150);
        for (int aw = 0; aw < 16; aw++) {
            table.addCell(new Cell().add(new Paragraph("hi")));
        }
        table.setMarginLeft(25);
        doc.add(table);
 
        doc.close();
    }
}
IndentationInCell.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2019 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/**
 * Example written by Bruno Lowagie in answer to the following question:
 * http://stackoverflow.com/questions/27873550/how-to-indent-text-inside-a-pdfpcell
 */
package com.itextpdf.samples.sandbox.tables;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
 
import java.io.File;
 
public class IndentationInCell {
    public static final String DEST = "./target/sandbox/tables/indentation_in_cell.pdf";
 
    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new IndentationInCell().manipulatePdf(DEST);
    }
 
    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
 
        Table table = new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth();
        Cell cell;
        cell = new Cell().add(new Paragraph("TO:\n\n   name"));
        table.addCell(cell);
        cell = new Cell().add(new Paragraph("TO:\n\n\u00a0\u00a0\u00a0name"));
        table.addCell(cell);
        cell = new Cell();
        cell.add(new Paragraph("TO:"));
        Paragraph p = new Paragraph("name");
        p.setMarginLeft(10);
        cell.add(p);
        table.addCell(cell);
        cell = new Cell();
        cell.add(new Paragraph("TO:"));
        p = new Paragraph("name");
        p.setTextAlignment(TextAlignment.RIGHT);
        cell.add(p);
        table.addCell(cell);
        doc.add(table);
 
        doc.close();
    }
}
LeadingInCell.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2019 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/**
 * Example written by Bruno Lowagie in answer to:
 * http://stackoverflow.com/questions/20145742/spacing-leading-pdfpcells-elements
 */
package com.itextpdf.samples.sandbox.tables;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
 
import java.io.File;
 
public class LeadingInCell {
    public static final String DEST = "./target/sandbox/tables/leading_in_cell.pdf";
 
    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new LeadingInCell().manipulatePdf(DEST);
    }
 
    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
 
        Table table = new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth();
        table.setWidth(UnitValue.createPercentValue(60));
        Cell cell = new Cell();
        Paragraph p;
        p = new Paragraph("paragraph 1: leading 16. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(16);
        cell.add(p);
        p = new Paragraph("paragraph 2: leading 32. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(32);
        cell.add(p);
        p = new Paragraph("paragraph 3: leading 10. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(10);
        cell.add(p);
        p = new Paragraph("paragraph 4: leading 18. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(18);
        cell.add(p);
        p = new Paragraph("paragraph 5: leading 40. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(40);
        cell.add(p);
        table.addCell(cell);
        doc.add(table);
 
        doc.close();
    }
}
SimpleTable4.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2019 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/**
 * Example written by Bruno Lowagie and Nishanthi Grashia in answer to the following question:
 * http://stackoverflow.com/questions/28073190/itext-maintain-identing-if-paragraph-takes-new-line-in-pdfpcell
 */
package com.itextpdf.samples.sandbox.tables;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
 
import java.io.File;
 
public class SimpleTable4 {
    public static final String DEST = "./target/sandbox/tables/simple_table4.pdf";
 
    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new SimpleTable4().manipulatePdf(DEST);
    }
 
    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
 
        // Here in itext7 there is only one way of adding paragraph to table. See itext5 example.
        Table table = new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth();
        Paragraph right = new Paragraph("This is right, because we create a paragraph with an indentation to the left and as we are adding the paragraph in composite mode, all the properties of the paragraph are preserved.");
        right.setMarginLeft(20);
        Cell rightCell = new Cell().add(right);
        table.addCell(rightCell);
        doc.add(table);
 
        doc.close();
    }
}
TableWithTab.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2019 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/**
 * This example is written by Bruno Lowagie in answer to the following question:
 * http://stackoverflow.com/questions/32593183/itextsharp-is-it-possible-to-set-a-different-alignment-in-the-same-cell-for-te
 */
package com.itextpdf.samples.sandbox.tables;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Tab;
import com.itextpdf.layout.element.TabStop;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.TabAlignment;
import com.itextpdf.layout.property.UnitValue;
 
import java.io.File;
 
public class TableWithTab {
    public static final String DEST = "./target/sandbox/tables/table_with_tab.pdf";
 
    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new TableWithTab().manipulatePdf(DEST);
    }
 
    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
 
        Table table = new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth();
        Paragraph p = new Paragraph();
        p.add("Left");
        p.addTabStops(new TabStop(1000, TabAlignment.RIGHT));
        p.add(new Tab());
        p.add("Right");
        table.addCell(p);
        doc.add(table);
        doc.close();
    }
}
CenteredTextInCell.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2019 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
 
using System;
using System.IO;
using iText.IO.Font.Constants;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
 
namespace iText.Samples.Sandbox.Tables
{
    public class CenteredTextInCell
    {
        public static readonly string DEST = "../../results/sandbox/tables/centered_text_in_cell.pdf";
 
        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
 
            new CenteredTextInCell().ManipulatePdf(DEST);
        }
 
        private void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
 
            PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
            Paragraph para = new Paragraph("Test").SetFont(font);
            para.SetFixedLeading(0);
            para.SetMultipliedLeading(1);
 
            Table table = new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth();
            Cell cell = new Cell();
            cell.SetMinHeight(50);
            cell.SetVerticalAlignment(VerticalAlignment.MIDDLE);
            cell.Add(para);
            table.AddCell(cell);
 
            doc.Add(table);
            
            doc.Close();
        }
    }
}
IndentTable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2019 iText Group NV
Authors: iText Software.
 
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
 
using System;
using System.IO;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
 
namespace iText.Samples.Sandbox.Tables
{
    public class IndentTable
    {
        public static readonly string DEST = "../../results/sandbox/tables/indent_table.pdf";
 
        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
 
            new IndentTable().ManipulatePdf(DEST);
        }
 
        private void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
 
            PdfCanvas cb = new PdfCanvas(pdfDoc.AddNewPage());
            cb.MoveTo(36, 842);
            cb.LineTo(36, 0);
            cb.Stroke();
 
            Table table = new Table(UnitValue.CreatePercentArray(8));
            table.SetHorizontalAlignment(HorizontalAlignment.LEFT);
            table.SetWidth(150);
 
            for (int aw = 0; aw < 16; aw++)
            {
                table.AddCell(new Cell().Add(new Paragraph("hi")));
            }
 
            table.SetMarginLeft(25);
 
            doc.Add(table);
 
            doc.Close();
        }
    }
}
IndentationInCell.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2019 iText Group NV
Authors: iText Software.
 
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
 
using System;
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
 
namespace iText.Samples.Sandbox.Tables
{
    public class IndentationInCell
    {
        public static readonly string DEST = "../../results/sandbox/tables/indentation_in_cell.pdf";
 
        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
 
            new IndentationInCell().ManipulatePdf(DEST);
        }
 
        private void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
 
            Table table = new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth();
            
            Cell cell = new Cell().Add(new Paragraph("TO:\n\n   name"));
            table.AddCell(cell);
 
            cell = new Cell().Add(new Paragraph("TO:\n\n\u00a0\u00a0\u00a0name"));
            table.AddCell(cell);
 
            cell = new Cell();
            cell.Add(new Paragraph("TO:"));
            Paragraph p = new Paragraph("name");
            p.SetMarginLeft(10);
            cell.Add(p);
            table.AddCell(cell);
 
            cell = new Cell();
            cell.Add(new Paragraph("TO:"));
            p = new Paragraph("name");
            p.SetTextAlignment(TextAlignment.RIGHT);
            cell.Add(p);
            table.AddCell(cell);
 
            doc.Add(table);
 
            doc.Close();
        }
    }
}
LeadingInCell.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2019 iText Group NV
Authors: iText Software.
 
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
 
using System;
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
 
namespace iText.Samples.Sandbox.Tables
{
    public class LeadingInCell
    {
        public static readonly string DEST = "../../results/sandbox/tables/leading_in_cell.pdf";
 
        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
 
            new LeadingInCell().ManipulatePdf(DEST);
        }
 
        private void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
 
            Table table = new Table(UnitValue.CreatePercentArray(1));
            table.SetWidth(UnitValue.CreatePercentValue(60));
 
            Cell cell = new Cell();
            
            Paragraph p = new Paragraph("paragraph 1: leading 16. Text to force a wrap and check the leading. Ha-ha")
                .SetFixedLeading(16);
            cell.Add(p);
 
            p = new Paragraph("paragraph 2: leading 32. Text to force a wrap and check the leading. Ha-ha")
                .SetFixedLeading(32);
            cell.Add(p);
 
            p = new Paragraph("paragraph 3: leading 10. Text to force a wrap and check the leading. Ha-ha")
                .SetFixedLeading(10);
            cell.Add(p);
 
            p = new Paragraph("paragraph 4: leading 18. Text to force a wrap and check the leading. Ha-ha")
                .SetFixedLeading(18);
            cell.Add(p);
 
            p = new Paragraph("paragraph 5: leading 40. Text to force a wrap and check the leading. Ha-ha")
                .SetFixedLeading(40);
            cell.Add(p);
 
            table.AddCell(cell);
 
            doc.Add(table);
 
            doc.Close();
        }
    }
}
SimpleTable4.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2019 iText Group NV
Authors: iText Software.
 
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
 
using System;
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
 
namespace iText.Samples.Sandbox.Tables
{
    public class SimpleTable4
    {
        public static readonly string DEST = "../../results/sandbox/tables/simple_table4.pdf";
 
        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
 
            new SimpleTable4().ManipulatePdf(DEST);
        }
 
        private void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
 
            Table table = new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth();
           
            Paragraph right = new Paragraph(
                "This is right, because we create a paragraph with an indentation to the left and as we are adding" +
                " the paragraph in composite mode, all the properties of the paragraph are preserved.");
 
            right.SetMarginLeft(20);
 
            Cell rightCell = new Cell().Add(right);
            table.AddCell(rightCell);
 
            doc.Add(table);
 
            doc.Close();
        }
    }
}
TableWithTab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2019 iText Group NV
Authors: iText Software.
 
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
 
using System;
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
 
namespace iText.Samples.Sandbox.Tables
{
    public class TableWithTab
    {
        public static readonly string DEST = "../../results/sandbox/tables/table_with_tab.pdf";
 
        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
 
            new TableWithTab().ManipulatePdf(DEST);
        }
 
        private void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
 
            Table table = new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth();
            Paragraph p = new Paragraph();
            p.Add("Left");
            p.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
            p.Add(new Tab());
            p.Add("Right");
            table.AddCell(p);
 
            doc.Add(table);
 
            doc.Close();
        }
    }
}

Click the following link to see the legacy example for iText 5. Except for security fixes, iText 5 is no longer being developed.



Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now