Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set the table cell width in iText java pdf

Tags:

java

itext

I am using the opensource http://itextpdf.com/ , to create some pdf .

I could create a table , but width of all column are same , I need to change the width of the particular column .

PdfPTable table = new PdfPTable(6);
Phrase tablePhrse = new Phrase("Sl n0", normalFontBold);
    PdfPCell c1 = new PdfPCell(tablePhrse);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

I could not find any method to set the width of the column , pls suggest some way to do achieve this ..

like image 901
indra Avatar asked Feb 08 '13 17:02

indra


People also ask

How to set table width in iText Pdf?

We can set the width of a table using the setWidthPercentage() method of the com. itextpdf. text.

What is iText format?

iText is a Java library originally created by Bruno Lowagie which allows to create PDF, read PDF and manipulate them. The following tutorial will show how to create PDF files with iText. This tutorial assumes that you have basis Java and Eclipse knowledge.

What is iText jar used for?

iText is a library for creating and manipulating PDF files in Java and.NET. iText was written by Bruno Lowagie. The source code was initially distributed as open source under the Mozilla Public License or the GNU Library General Public License open source licenses. However, as of version 5.0.

Is iText free for commercial use?

This license is a commercial license. You have to pay for it. To answer your question: iText can be used for free in situations where you also distribute your software for free. As soon as you want to use iText in a closed source, proprietary environment, you have to pay for your use of iText.


2 Answers

Try this.

float[] columnWidths = new float[]{10f, 20f, 30f, 10f};
table.setWidths(columnWidths);
like image 181
Sujeet Kumar Avatar answered Sep 21 '22 16:09

Sujeet Kumar


You can make use of setWidths() method.

table.setWidths(new int[]{200,50});

public void setWidths(int[] relativeWidths)

like image 34
Smit Avatar answered Sep 22 '22 16:09

Smit