Skip to content

Commit 0908af2

Browse files
SnipxiText-CI
authored andcommitted
Fix processing inline-block images as children of <body> tag
DEVSIX-2834
1 parent db28889 commit 0908af2

File tree

9 files changed

+90
-8
lines changed

9 files changed

+90
-8
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,9 @@ public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext conte
135135
postProcessInlineGroup();
136136
div.add((AreaBreak) element);
137137
processed = true;
138-
} else if (childTagWorker instanceof ImgTagWorker && element instanceof IElement) {
139-
if (CssConstants.BLOCK.equals(((ImgTagWorker) childTagWorker).getDisplay())) {
140-
processed = addBlockChild((com.itextpdf.layout.element.IElement) element);
141-
} else if (childTagWorker.getElementResult() instanceof Image) {
142-
inlineHelper.add((ILeafElement) childTagWorker.getElementResult());
143-
processed = true;
144-
}
138+
} else if (childTagWorker instanceof ImgTagWorker && element instanceof IElement && !CssConstants.BLOCK.equals(((ImgTagWorker) childTagWorker).getDisplay())) {
139+
inlineHelper.add((ILeafElement) childTagWorker.getElementResult());
140+
processed = true;
145141
} else if (element instanceof com.itextpdf.layout.element.IElement) {
146142
processed = addBlockChild((com.itextpdf.layout.element.IElement) element);
147143
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,21 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.html2pdf.attach.impl.layout.HtmlDocumentRenderer;
4848
import com.itextpdf.html2pdf.attach.impl.layout.form.element.IFormField;
4949
import com.itextpdf.html2pdf.attach.util.WaitingInlineElementsHelper;
50+
import com.itextpdf.html2pdf.css.CssConstants;
5051
import com.itextpdf.kernel.pdf.PdfDocument;
5152
import com.itextpdf.layout.Document;
5253
import com.itextpdf.layout.IPropertyContainer;
5354
import com.itextpdf.layout.element.AreaBreak;
5455
import com.itextpdf.layout.element.IBlockElement;
56+
import com.itextpdf.layout.element.IElement;
5557
import com.itextpdf.layout.element.ILeafElement;
5658
import com.itextpdf.layout.element.Image;
5759
import com.itextpdf.layout.font.FontFamilySplitter;
5860
import com.itextpdf.layout.property.Property;
59-
import com.itextpdf.html2pdf.css.CssConstants;
6061
import com.itextpdf.styledxmlparser.css.ICssResolver;
6162
import com.itextpdf.styledxmlparser.node.IElementNode;
6263
import com.itextpdf.styledxmlparser.node.INode;
64+
6365
import java.util.List;
6466

6567
/**
@@ -145,6 +147,9 @@ public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext conte
145147
} else if (childTagWorker instanceof BrTagWorker) {
146148
inlineHelper.add((ILeafElement) childTagWorker.getElementResult());
147149
processed = true;
150+
} else if (childTagWorker instanceof ImgTagWorker && childTagWorker.getElementResult() instanceof IElement && !CssConstants.BLOCK.equals(((ImgTagWorker) childTagWorker).getDisplay())) {
151+
inlineHelper.add((ILeafElement) childTagWorker.getElementResult());
152+
processed = true;
148153
} else if (childTagWorker.getElementResult() != null) {
149154
processed = processBlockChild(childTagWorker.getElementResult());
150155
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.html2pdf.element;
44+
45+
46+
import com.itextpdf.html2pdf.HtmlConverter;
47+
import com.itextpdf.kernel.utils.CompareTool;
48+
import com.itextpdf.test.ExtendedITextTest;
49+
import com.itextpdf.test.annotations.type.IntegrationTest;
50+
import org.junit.Assert;
51+
import org.junit.BeforeClass;
52+
import org.junit.Test;
53+
import org.junit.experimental.categories.Category;
54+
55+
import java.io.File;
56+
import java.io.IOException;
57+
58+
@Category(IntegrationTest.class)
59+
public class ImageTest extends ExtendedITextTest {
60+
61+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/html2pdf/element/ImageTest/";
62+
public static final String destinationFolder = "./target/test/com/itextpdf/html2pdf/element/ImageTest/";
63+
64+
@BeforeClass
65+
public static void beforeClass() {
66+
createDestinationFolder(destinationFolder);
67+
}
68+
69+
@Test
70+
public void imagesInBodyTest() throws IOException, InterruptedException {
71+
HtmlConverter.convertToPdf(new File(sourceFolder + "imagesInBody.html"), new File(destinationFolder + "imagesInBody.pdf"));
72+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "imagesInBody.pdf", sourceFolder + "cmp_imagesInBody.pdf", destinationFolder, "diff18_"));
73+
}
74+
75+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
293 Bytes
Loading
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<img src="100x100placeholder.png"><img src="100x100placeholder.png"><img src="100x100placeholder.png">
5+
</body>
6+
</html>

0 commit comments

Comments
 (0)