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:

 

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

I adapted your example like this:

Dim table As New PdfPTable(3)
table.WidthPercentage = 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.Padding = 0
    cell.HorizontalAlignment = alignment
    cell.Border = PdfPCell.NO_BORDER
    Return cell
End Function

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.

JavaScript errors detected

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

If this problem persists, please contact our support.