Skip to main content
Skip table of contents

Argument not specified in iTextSharp


I am getting the errors that cell.setPadding, cell.setHorizontalAlignment, cell.setBorder all are not member of iTextsharp.Text.pdf.PdfPCell.

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

NONE
Dim table As New PdfPTable(3)
table.setWidthPercentage(100)
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))
document.add(table)
 
Public Function getCell(ByVal text As String, ByVal alignment As Integer)
    As PdfPCell
Dim cell As New PdfPCell(New Phrase(text))
cell.setPadding(0)
cell.setHorizontalAlignment(alignment)
cell.setBorder(PdfPCell.NO_BORDER)
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:

JAVA
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));
doc.add(table);

And: public Cell getCell(String text, TextAlignment alignment) { Cell cell = new Cell().add(new Paragraph(text)); cell.setPadding(0); cell.setTextAlignment(alignment); cell.setBorder(Border.NO_BORDER); return cell; }

Click Argument not specified in iTextSharp if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.