Skip to content

Commit 0dffa42

Browse files
committed
Support inline-block display inside of table cell
DEVSIX-1746
1 parent ebd6f2c commit 0dffa42

File tree

6 files changed

+100
-1
lines changed

6 files changed

+100
-1
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/TdTagWorker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ public boolean processContent(String content, ProcessorContext context) {
109109
@Override
110110
public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext context) {
111111
boolean processed = false;
112-
if (childTagWorker instanceof SpanTagWorker) {
112+
if (childTagWorker instanceof IDisplayAware && CssConstants.INLINE_BLOCK.equals(((IDisplayAware) childTagWorker).getDisplay()) && childTagWorker.getElementResult() instanceof IBlockElement) {
113+
inlineHelper.add((IBlockElement) childTagWorker.getElementResult());
114+
processed = true;
115+
} else if (childTagWorker instanceof SpanTagWorker) {
113116
boolean allChildrenProcesssed = true;
114117
for (IPropertyContainer propertyContainer : ((SpanTagWorker) childTagWorker).getAllElements()) {
115118
if (propertyContainer instanceof ILeafElement) {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ This file is part of the iText (R) project.
4242
*/
4343
package com.itextpdf.html2pdf.css;
4444

45+
import com.itextpdf.html2pdf.ConverterProperties;
4546
import com.itextpdf.html2pdf.HtmlConverter;
4647
import com.itextpdf.io.LogMessageConstant;
4748
import com.itextpdf.kernel.geom.PageSize;
@@ -244,4 +245,20 @@ public void displayInlineBlock17Test() throws IOException, InterruptedException
244245
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "display_inline-block17.pdf", sourceFolder + "cmp_display_inline-block17.pdf", destinationFolder, "diff19_"));
245246
}
246247

248+
@Test
249+
@LogMessages(messages = @LogMessage(messageTemplate = com.itextpdf.html2pdf.LogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION, count = 7))
250+
public void inlineBlockInsideTableCellTest() throws IOException, InterruptedException {
251+
252+
// IO setup
253+
PdfWriter writer = new PdfWriter(new File(destinationFolder + "inlineBlockInsideTableCellTest.pdf"));
254+
PdfDocument pdfDocument = new PdfDocument(writer);
255+
pdfDocument.setDefaultPageSize(new PageSize(1000f, 1450f));
256+
257+
// properties
258+
ConverterProperties props = new ConverterProperties();
259+
props.setBaseUri(sourceFolder);
260+
261+
HtmlConverter.convertToPdf(new FileInputStream(new File(sourceFolder + "inlineBlockInsideTableCellTest.html")), pdfDocument, props);
262+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "inlineBlockInsideTableCellTest.pdf", sourceFolder + "cmp_inlineBlockInsideTableCell.pdf", destinationFolder, "diffinlineBlockInsideTableCellTest_"));
263+
}
247264
}
Binary file not shown.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<!DOCTYPE html>
2+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3+
4+
<head>
5+
<title>Hello</title>
6+
<style>
7+
.TemplatePage {
8+
width: 970px;
9+
height: 1375px;
10+
position: relative;
11+
border: 1px solid grey;
12+
}
13+
14+
.tabPageBody {
15+
width: 100%;
16+
}
17+
18+
.divTemplateCol {
19+
margin-top: 0px;
20+
float: top;
21+
display: inline-block;
22+
vertical-align: top;
23+
}
24+
</style>
25+
</head>
26+
27+
<body>
28+
<div class="TemplatePage">
29+
30+
<div>
31+
<table class="tabPageBody" style="display: table;">
32+
<tbody>
33+
<tr>
34+
<td align="center" colspan="2">
35+
<div class="divTemplateCol">
36+
<div style="margin: 0px; border: 0px solid rgb(70, 70, 70); border-image: none; width: 940px; height: 60px;">
37+
</div>
38+
</div>
39+
</td>
40+
</tr>
41+
<tr>
42+
<td align="center" colspan="1">
43+
<div class="divTemplateCol">
44+
<div style="border-width: 2px 2px 0px; border-style: solid; border-color: rgb(70, 70, 70); margin: 0px 0px 0px 20px; width: 270px; min-height: 450px;">
45+
<table style="width: 270px; height: 450px;">
46+
</table>
47+
</div>
48+
</div>
49+
<div class="divTemplateCol">
50+
<div style="border-width: 0px 2px 2px; border-style: solid; border-color: rgb(70, 70, 70); margin: -5px 0px 0px 20px; width: 270px; min-height: 440px;">
51+
<table style="width: 270px; height: 440px;">
52+
</table>
53+
</div>
54+
</div>
55+
</td>
56+
<td align="center" colspan="1">
57+
<div class="divTemplateCol">
58+
<div style="margin: 0px; width: 630px; height: 0px; border-top-color: rgb(114, 114, 114); border-top-width: 3px; border-top-style: solid;"></div>
59+
</div>
60+
<div class="divTemplateCol">
61+
<div style="margin: 0px; border: 0px solid rgb(70, 70, 70); width: 305px; height: 290px; position: relative; min-height: 290px;"><img width="305" height="290" src="pexels-photo-631292.jpeg" />
62+
</div>
63+
</div>
64+
<div class="divTemplateCol">
65+
<div style="margin: 0px 5px; width: 0px; height: 280px; border-right-color: rgb(118, 118, 118); border-right-width: 3px; border-right-style: solid;"></div>
66+
</div>
67+
<div class="divTemplateCol">
68+
<div style="margin: 0px; border: 0px solid rgb(70, 70, 70); width: 305px; height: 285px; position: relative; min-height: 285px;"><img width="305" height="285" src="pexels-photo-767138.jpeg" />
69+
</div>
70+
</div>
71+
</td>
72+
</tr>
73+
</tbody>
74+
</table>
75+
</div>
76+
</div>
77+
</body>
78+
79+
</html>
158 KB
Loading
183 KB
Loading

0 commit comments

Comments
 (0)