Argument not specified in iTextSharp

Tags: iText vs iTextSharptablesalignmentcelliText 7

As per suggestion by Bruno Lowagie, I am using the following code:

Dim table As New PdfPTable(3)
table.addCell(getCell("Text to the left", PdfPCell.ALIGN_LEFT))
table.addCell(getCell("Text in the middle", PdfPCell.ALIGN_CENTER))
table.addCell(getCell("Text to the right", PdfPCell.ALIGN_RIGHT))
Public Function getCell(ByVal text As String, ByVal alignment As Integer)
    As PdfPCell
Dim cell As New PdfPCell(New Phrase(text))
Return cell
End Function
But I am getting the errors that cell.setPadding, cell.setHorizontalAlignment, cell.setBorder all are not member of iTextsharp.Text.pdf.PdfPCell. Also table.setWidthPercentage(100) shows the error argument not specified parameter.

Posted on StackOverflow on Apr 11, 2015 by Sunil Bhagwat

This is commonly known:

  • Methods in Java start with lower case; methods in .NET start with upper case, so when people ask you to use Java code as pseudo code and to convert Java to .NET, you need to change methods such as add() and addCell() into Add() and AddCell().

  • Member-variables in Java are changed and consulted using getters and setters; variables in .NET are changed and consulted using methods that look like properties. This means the you need to change lines such as cell.setBorder(border); and border = cell.getBorder(); into cell.Border = border and border = cell.Border.

iText and iTextSharp are kept in sync, which means that, using the two rules explained above, a developer won't have any problem to convert iText code into iTextSharp code.

Here is your code in Java adapted to iText 7:

Table table = new Table(3);
table.addCell(getCell("Text to the left", TextAlignment.LEFT));
table.addCell(getCell("Text in the middle", TextAlignment.CENTER));
table.addCell(getCell("Text to the right", TextAlignment.RIGHT));


public Cell getCell(String text, TextAlignment alignment) {
    Cell cell = new Cell().add(new Paragraph(text));
    return cell;

Click this link if you want to see how to answer this question in iText 5.