iTextSharp Conversion from Table to pdfPTable
I have an old ASP.NET project originally done in ASP.NET 1.1 w/ iText.NET and converted to .NET 2.0 and iTextSharp 4.1.6.0. It uses lots of Table (I'm assuming pdfptable wasn't an option at the time it was created.) I am trying to convert this code to use the latest iTextSharp 5.0.0 dll and now see Table and cell have been removed. I started converting it anyway and soon found there is no equivalent to a lot of the functionality that Table offered. Mainly AddCell no longer allows a col,row setting. There are literally thousands of these calls in this 开发者_JAVA百科code and the posibility of changing it to generate linearly row by row looks hopeless at the moment. The current code looks something like:
Dim myTable As New Table(NumReq + 2, IngDS.Tables(0).Rows.Count + 3)
myTable.SetWidths(Width)
myTable.Width = 100
myTable.Padding = 2
myCell = New Cell(New Phrase("Some Text", New iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK)))
myCell.SetHorizontalAlignment(Element.ALIGN_RIGHT)
myCell.GrayFill = 0.75
myTable.AddCell(myCell, Row, Col)
myCell = New Cell(New Phrase("Other Text",New iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK)))
myCell.GrayFill = 0.75
myTable.AddCell(myCell, Row, Col+1)
Before I embark down that road I was hoping someone would be able to point me in a direction that I'm just totally missing that will make this conversion much more simple.
Any ideas?
Thanks.
You do not need to specify the row and column in the AddCell method anymore. Calling the AddCell method just adds whatever you're adding to the next cell. So, if you have a table with two rows and two columns calling AddCell the first time will add it to row 1 column 1. The second time it's called it will add it to row 1 column 2. The next time it will add it to row 2 column 1 and so on.
If you want to skip a call AddCell("") to put nothing into the cell and skip it.
精彩评论