Questions tagged [pdfptable]

Table class used by iTextPdf (iText and iTextSharp) versions 5.x for generating tables

PdfPTable is the class for creating tables in (Java) and (.Net).

This is a very simple example of its use:

/**
 * Example written by Bruno Lowagie and Nishanthi Grashia in answer to the following question:
 * https://stackoverflow.com/questions/24359321/adding-row-to-a-table-in-pdf-using-itext
 */
@WrapToTest
public class SimpleTable
{
    public static final String DEST = "results/tables/simple_table.pdf";

    public static void main(String[] args) throws IOException, DocumentException
    {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new SimpleTable().createPdf(DEST);
    }

    public void createPdf(String dest) throws IOException, DocumentException
    {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.open();
        PdfPTable table = new PdfPTable(8);
        for(int aw = 0; aw < 16; aw++)
        {
            table.addCell("hi");
        }
        document.add(table);
        document.close();
    }
}

(101 - a very simple table)

Many more examples illustrating how to build more complex tables, can be found in the examples section of itextpdf.com.

107 questions
3
votes
1 answer

Multiple Table Column alignment in iTextsharp

I am creating a table where each column has its own alignment as shown below. How do I accomplish it at column level than at cell level?
Null Head
  • 2,877
  • 13
  • 61
  • 83
3
votes
3 answers

iTextSharp and moving some data to next page

I am creating an invoice using the iTextSharp. That displays nicely but sometime, when invoice items are larger in qty, the summary portion (which displays subtotal, tax, discounts, grand total etc) is splitted. Some displayes in current page and…
Sameers Javed
  • 342
  • 2
  • 5
  • 16
3
votes
2 answers

Using ItextSharp PdfPTable, table.TotalHeight returns 0.0, but expecting a positive float value

I'm using ItextSharp to create a PDF document with multiple PdfPTables. I group multiple PdfPTables using a list, and the list is created in a function and returned as a list. I then take the list and loop through it to add each PdfPTable to the…
Stanfrancisco
  • 352
  • 1
  • 7
  • 24
3
votes
2 answers

unable to calculate itext PdfPTable/PdfPCell height properly

I'm facing a problem while trying to generate a PdfPTable and calculate its height before adding it to a document. The method calculateHeights of PdfPTable returned the height a lot greater than the height of a page (while the table is about 1/4 of…
Anton Zvonovsky
  • 313
  • 2
  • 6
  • 16
3
votes
3 answers

Add a column to PdfPTable, iTextSharp

I'm creating a PDF document using iTextSharp. I see how to create a new table with a number of columns but I can't see anyway to dynamically add a new column. The problem I have is I'm not going to know the number of columns I need straight away, so…
mat-mcloughlin
  • 6,492
  • 12
  • 45
  • 62
3
votes
1 answer

How to insert a PdfPTable into an existing PDF template?

Update: After some discussion, we decided to go with TeX, specifically the windows compatible MiKTeX. We realised that even if we could get the dynamic lengthed table formatted by micromanaging the layout (which doesn't seem possible or is as…
Joe
  • 11,147
  • 7
  • 49
  • 60
2
votes
1 answer

Is it possible to have space between cells in iTextPdf?

Does iTextPdf allow to set spacing between cells in table? I have a table with 2 columns and I am trying to draw a border-bottom on cell. I want space between each border same as cell padding. I am using below code: PdfPTable table = new…
Karsan
  • 269
  • 3
  • 14
2
votes
1 answer

iTextSharp pdfpTable flowing in two columns in same page

I am using iTextSharp PdfPTtable for creating tables from a database. When the table is lengthy (long but just with 3 columns), I managed to get the table flowing (or continuing) to the next PDF page. But I want them to continue in the right side…
user1429309
  • 57
  • 1
  • 4
2
votes
1 answer

iTextSharp PdfPCell Alignment with Chunk

I am creating a PDF programmatically using iTextSharp and generating a PdfPTable. In some of the cells I need to have a hyperlink. Without a hyperlink I can align the text in the cell horizontally and vertically, however when I add in the chunk…
Adam92
  • 436
  • 8
  • 23
2
votes
1 answer

The table width must be greater than zero exception when using nested tables

I am trying to use nested tables with iText. I get a DocumentException: The table width must be greater than zero. The outer table has 16 columns. I call a method that passes in the outer table. This method adds two inner tables. If I add either…
Greg
  • 57
  • 1
  • 2
  • 7
2
votes
1 answer

iText combining rowspan and colspan - PDFPTable

Working on a calendar projcet and using iText to generate a pdf to print appointments. I can plot a cell with a colspan, and a cell with a rowspan, but I can't combine it. Table has width of 4 cells. I want to achieve something like…
Pega88
  • 564
  • 1
  • 6
  • 16
2
votes
0 answers

Add page title between PdfPTables in iText

I have a number of PdfPTables that is following each other like this: Is it possible to add a title on all of the page(not just the first page)? I believe I cant use the PdfPageEventHelper because the table that is first on each page needs to be…
Grains
  • 950
  • 3
  • 16
  • 35
2
votes
2 answers

How to reduce memory consumption of PdfPTable with many cells

I'm creating a PDF using ITextSharp which is composed of a single PdfTable. Unfortunately for a particular data set, I'm getting an Out of memory Exception due to the large number PdfPCells that are created (I've profiled the memory usage - I've…
Tom Carter
  • 2,938
  • 1
  • 27
  • 42
1
vote
2 answers

Adding page number in header cell in every page

I am creating a pdf document. There is a PdfPTable in which some rows that will repeated in every page. What I want is to add page number in that table cell on each page. I tried by rendering cell in PdfPageEventHelper and write table in…
Zan
  • 31
  • 3
1
vote
0 answers

Getting IOException:The document has no pages in Itext Pdf

I am trying to create a Pdf for my application. I am creating a table as follows:- boolean isTableHeaderCreated = false; PdfPTable playerTable = null; Set keySet = playersListMap.keySet(); for(String key:keySet) { …
Manish
  • 1,274
  • 3
  • 22
  • 59