Skip to content

Commit 6cf0f3e

Browse files
Process white-space css property for page margin boxes content
DEVSIX-1905
1 parent 1388ced commit 6cf0f3e

File tree

11 files changed

+234
-7
lines changed

11 files changed

+234
-7
lines changed

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/PageContextProcessor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
This file is part of the iText (R) project.
33
Copyright (c) 1998-2017 iText Group NV
44
Authors: Bruno Lowagie, Paulo Soares, et al.
5-
5+
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU Affero General Public License version 3
88
as published by the Free Software Foundation with the addition of the
99
following permission added to Section 15 as permitted in Section 7(a):
1010
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
1111
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
1212
OF THIRD PARTY RIGHTS
13-
13+
1414
This program is distributed in the hope that it will be useful, but
1515
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1616
or FITNESS FOR A PARTICULAR PURPOSE.
@@ -20,23 +20,23 @@ This file is part of the iText (R) project.
2020
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
2121
Boston, MA, 02110-1301 USA, or download the license from the following URL:
2222
http://itextpdf.com/terms-of-use/
23-
23+
2424
The interactive user interfaces in modified source and object code versions
2525
of this program must display Appropriate Legal Notices, as required under
2626
Section 5 of the GNU Affero General Public License.
27-
27+
2828
In accordance with Section 7(b) of the GNU Affero General Public License,
2929
a covered work must retain the producer line in every PDF that is created
3030
or manipulated using iText.
31-
31+
3232
You can be released from the requirements of the license by purchasing
3333
a commercial license. Buying such a license is mandatory as soon as you
3434
develop commercial activities involving the iText software without
3535
disclosing the source code of your own applications.
3636
These activities include: offering paid services to customers as an ASP,
3737
serving PDFs on the fly in a web application, shipping iText with a closed
3838
source product.
39-
39+
4040
For more information, please contact iText Software Corp. at this
4141
address: sales@itextpdf.com
4242
*/
@@ -490,6 +490,7 @@ private void createMarginBoxesElements(List<PageMarginBoxContextNode> resolvedPa
490490

491491
// TODO it would be great to reuse DefaultHtmlProcessor, but it seems there is no convenient way of doing so, and maybe it would be an overkill
492492
IElementNode dummyMarginBoxNode = new JsoupElementNode(new Element(Tag.valueOf(TagConstants.DIV), ""));
493+
dummyMarginBoxNode.setStyles(boxStyles);
493494
DivTagWorker marginBoxWorker = new DivTagWorker(dummyMarginBoxNode, context);
494495
for (int i = 0; i < marginBoxContentNode.childNodes().size(); i++) {
495496
INode childNode = marginBoxContentNode.childNodes().get(i);

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,23 @@ public void marginBoxTest04() throws IOException, InterruptedException {
150150
runTest("marginBoxTest04");
151151
}
152152

153-
private void runTest(String name) throws IOException, InterruptedException {
153+
154+
@Test
155+
public void marginBoxMultilineTest01() throws IOException, InterruptedException {
156+
runTest("marginBoxMultilineTest01");
157+
}
158+
159+
@Test
160+
public void marginBoxMultilineTest02() throws IOException, InterruptedException {
161+
runTest("marginBoxMultilineTest02");
162+
}
163+
164+
@Test
165+
public void marginBoxMultilineTest03() throws IOException, InterruptedException {
166+
runTest("marginBoxMultilineTest03");
167+
}
168+
169+
private void runTest(String name) throws IOException, InterruptedException {
154170
String htmlPath = sourceFolder + name + ".html";
155171
String pdfPath = destinationFolder + name + ".pdf";
156172
String cmpPdfPath = sourceFolder + "cmp_" + name + ".pdf";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ public void escapedStringTest04() throws IOException, InterruptedException {
174174
runTest("escapedStringTest04");
175175
}
176176

177+
@Test
178+
public void escapedStringTest05() throws IOException, InterruptedException {
179+
runTest("escapedStringTest05");
180+
}
181+
177182
@Test
178183
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.CONTENT_PROPERTY_INVALID, count = 5))
179184
public void attrTest01() throws IOException, InterruptedException {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style type="text/css">
5+
@page {
6+
font-size: 8pt;
7+
@top-left {
8+
background-color: #ccc;
9+
border: solid 1pt;
10+
content: "Header mulitline attempt \r is it a new line?";
11+
}
12+
@top-center {
13+
background-color: #ccc;
14+
border: solid 1pt;
15+
content: "Header mulitline attempt \r\n is it a new line?";
16+
}
17+
@top-right {
18+
background-color: #ccc;
19+
border: solid 1pt;
20+
content: "Header mulitline attempt \n is it a new line?";
21+
}
22+
@bottom-left {
23+
background-color: #ccc;
24+
border: solid 1pt;
25+
content: "Footer mulitline attempt \000 ais it a new line?";
26+
}
27+
@bottom-center {
28+
background-color: #ccc;
29+
border: solid 1pt;
30+
content: "Footer mulitline attempt \a is it a new line?";
31+
}
32+
@bottom-right {
33+
background-color: #ccc;
34+
border: solid 1pt;
35+
content: "Footer mulitline attempt \u000a is it a new line?";
36+
}
37+
}
38+
</style>
39+
</head>
40+
<body>
41+
<div style="background-color: yellow;">
42+
No new lines should be processed with default value of white-space css property.
43+
</div>
44+
</body>
45+
</html>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style type="text/css">
5+
@page {
6+
font-size: 8pt;
7+
white-space: pre;
8+
@top-left {
9+
background-color: #ccc;
10+
border: solid 1pt;
11+
content: "Header mulitline attempt \r is it a new line?";
12+
}
13+
@top-center {
14+
background-color: #ccc;
15+
border: solid 1pt;
16+
content: "Header mulitline attempt \r\n is it a new line?";
17+
}
18+
@top-right {
19+
background-color: #ccc;
20+
border: solid 1pt;
21+
content: "Header mulitline attempt \n is it a new line?";
22+
}
23+
@bottom-left {
24+
background-color: #ccc;
25+
border: solid 1pt;
26+
content: "Footer mulitline attempt \000a is it a new line?";
27+
}
28+
@bottom-center {
29+
background-color: #ccc;
30+
border: solid 1pt;
31+
content: "Footer mulitline attempt \a is it a new line?";
32+
}
33+
@bottom-right {
34+
background-color: #ccc;
35+
border: solid 1pt;
36+
content: "Footer mulitline attempt \u000a is it a new line?";
37+
}
38+
}
39+
</style>
40+
</head>
41+
<body>
42+
<div style="background-color: yellow;">
43+
Only @bottom-center and @bottom-left margin boxes are expected to contain multiline content.
44+
All margin boxes has white-space property set to `pre`.
45+
</div>
46+
</body>
47+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style type="text/css">
5+
@page {
6+
font-size: 8pt;
7+
size: 8in 2in;
8+
@bottom-center {
9+
white-space: pre;
10+
background-color: #ccc;
11+
border: solid 1pt;
12+
content: "Footer mulitline attempt \a is it a new line?";
13+
}
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<div style="background-color: yellow;">
19+
@bottom-center margin box is expected to contain multiline content.
20+
White-space property set to `pre`.
21+
</div>
22+
</body>
23+
</html>

0 commit comments

Comments
 (0)