Reputation: 51
I generated a PDF file starting from an HTML page using iTextSharp. But tables are rendered with the last column not justified, as you can see in the image.
What can I do to fix this?
Here's part of the code:
StyleSheet ss = new StyleSheet();
TextReader htmlReader = new StringReader(strHTML);
ArrayList htmlarraylist = HTMLWorker.ParseToList(htmlReader, ss);
foreach (IElement el in htmlarraylist)
{
document.Add(el);
}
In strHTML there is this HTML code:
<TABLE style="WIDTH: 100%" border=1 cellSpacing=1 cellPadding=1><BR><TBODY><BR><TR><BR><TD>1</TD><BR><TD>2</TD><BR><TD>4</TD><BR><TD>4</TD><BR><TD>5</TD></TR><BR><TR><BR><TD>6</TD><BR><TD>7</TD><BR><TD>8</TD><BR><TD>9</TD><BR><TD>0</TD></TR><BR><TR><BR><TD>0</TD><BR><TD>98</TD><BR><TD>7</TD><BR><TD>5</TD><BR><TD>4</TD></TR><BR><TR><BR><TD>3</TD><BR><TD>2</TD><BR><TD>3</TD><BR><TD>4</TD><BR><TD>5</TD></TR><BR><TR><BR><TD>76</TD><BR><TD>7</TD><BR><TD>9</TD><BR><TD>0</TD><BR><TD>4</TD></TR></TBODY></TABLE>
Upvotes: 1
Views: 545
Reputation: 51
I found the problem!
All those BR tags were messing up my tables! Those were added by a replace hided in another class:
Replace("\r\n", "<BR>");
Thank you guys for your help!
Upvotes: 0
Reputation: 1204
Ciao
do you use a loop to produce your pdf,? are you sure for each cell you make the appropriate aactions...
int howManyCell = ....
for (int i = 0; i < howManyCell + 1; i++) {
PdfPCell cell = new PdfPCell();
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
cell.VerticalAlignment = Element.ALIGN_TOP;
table.AddCell(cell);
}
Maybe do you use an automatic transformation, without any use of pdf class elements ? In thi case show us the header of your html table and a sample of the first table row, to check out if that is normal
Upvotes: 1