Skip to content

Commit cb5a2bb

Browse files
committed
Fix table with empty rows creation
DEVSIX-6094
1 parent dcc8edc commit cb5a2bb

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/main/java/com/itextpdf/html2pdf/attach/wrapelement/TableWrapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ public Table toTable(WaitingColgroupsHelper colgroupsHelper) {
269269
}
270270
if (rows != null) {
271271
for (int i = 0; i < rows.size(); i++) {
272+
table.startNewRow();
273+
272274
if (isRtl) {
273275
Collections.reverse(rows.get(i));
274276
}
277+
275278
for (int j = 0; j < rows.get(i).size(); j++) {
276279
table.addCell(rows.get(i).get(j).cell);
277280
}
278-
if (i != rows.size() - 1) {
279-
table.startNewRow();
280-
}
281281
}
282282
}
283283
if (caption != null) {

src/test/java/com/itextpdf/html2pdf/css/PageBreakTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ public void pageBreakInsideAvoidInTdWithParaTest() throws IOException, Interrupt
226226
}
227227

228228
@Test
229-
@LogMessages(messages = {@LogMessage(messageTemplate = LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)})
229+
@LogMessages(messages = {
230+
@LogMessage(messageTemplate = IoLogMessageConstant.LAST_ROW_IS_NOT_COMPLETE),
231+
@LogMessage(messageTemplate = LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)
232+
})
230233
// TODO: DEVSIX-5263 inconsistent behavior when page-break-inside: avoid set in td and td contains inline elements
231234
public void pageBreakInsideAvoidInTdWithTableTest() throws IOException, InterruptedException {
232235
convertToElements("pageBreakInsideAvoidInTdWithTable");

src/test/java/com/itextpdf/html2pdf/element/TableTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ This file is part of the iText (R) project.
3535
import com.itextpdf.layout.Document;
3636
import com.itextpdf.layout.element.IBlockElement;
3737
import com.itextpdf.layout.element.IElement;
38+
import com.itextpdf.layout.element.Table;
3839
import com.itextpdf.layout.logs.LayoutLogMessageConstant;
3940
import com.itextpdf.test.ExtendedITextTest;
4041
import com.itextpdf.test.annotations.LogMessage;
4142
import com.itextpdf.test.annotations.LogMessages;
4243
import com.itextpdf.test.annotations.type.IntegrationTest;
44+
4345
import org.junit.Assert;
4446
import org.junit.BeforeClass;
4547
import org.junit.Ignore;
@@ -603,6 +605,16 @@ public void thTagConvertToElementTest() throws IOException, InterruptedException
603605
runConvertToElements("thTagConvertToElement", false);
604606
}
605607

608+
@Test
609+
public void emptyRowsConvertToElementTest() throws IOException {
610+
FileInputStream source = new FileInputStream(sourceFolder + "emptyRowsConvertToElement.html");
611+
612+
for (IElement element : HtmlConverter.convertToElements(source)) {
613+
Assert.assertTrue(element instanceof Table);
614+
Assert.assertEquals(4, ((Table) element).getNumberOfRows());
615+
}
616+
}
617+
606618
@Test
607619
public void thTagConvertToPdfTest() throws IOException, InterruptedException {
608620
runTest("thTagConvertToPdf");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<table>
2+
<tr></tr>
3+
<tr></tr>
4+
<tr></tr>
5+
<tr>
6+
<td>test #1</td>
7+
<td>test #2</td>
8+
</tr>
9+
</table>

0 commit comments

Comments
 (0)