Argument not specified in iTextSharp

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));

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 this link if you want to see how to answer this question in iText 5.

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now