-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the probles was in line CSSParser.java:553 - the `margins` map was overriden by the new value. Previous map content was lost.
- Loading branch information
Showing
6 changed files
with
90 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
flying-saucer-pdf/src/test/java/org/xhtmlrenderer/pdf/HeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.xhtmlrenderer.pdf; | ||
|
||
import com.codeborne.pdftest.PDF; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
|
||
import static com.codeborne.pdftest.assertj.Assertions.assertThat; | ||
import static org.xhtmlrenderer.pdf.TestUtils.printFile; | ||
|
||
public class HeaderTest { | ||
private static final Logger log = LoggerFactory.getLogger(HeaderTest.class); | ||
|
||
@Test | ||
void pageWithHeader() throws IOException { | ||
String fileName = "page-with-header.html"; | ||
byte[] bytes = Html2Pdf.fromClasspathResource(fileName); | ||
|
||
PDF pdf = printFile(log, bytes, "page-with-header.pdf"); | ||
assertThat(pdf).containsText("Header", "Body", "Footer"); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
flying-saucer-pdf/src/test/java/org/xhtmlrenderer/pdf/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.xhtmlrenderer.pdf; | ||
|
||
import com.codeborne.pdftest.PDF; | ||
import org.slf4j.Logger; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
public class TestUtils { | ||
public static PDF printFile(Logger log, byte[] pdf, String filename) throws IOException { | ||
File file = new File("target", filename); | ||
try (FileOutputStream o = new FileOutputStream(file)) { | ||
o.write(pdf); | ||
} | ||
log.info("Generated PDF: {}", file.getAbsolutePath()); | ||
return new PDF(pdf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
flying-saucer-pdf/src/test/resources/page-with-header.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> | ||
|
||
<head> | ||
<style> | ||
@page { | ||
size: 200px 200px; | ||
@top-left { | ||
content: element(header); | ||
} | ||
@bottom-left { | ||
content: element(footer); | ||
} | ||
} | ||
|
||
#header { | ||
position: running(header); | ||
} | ||
|
||
#footer { | ||
position: running(footer); | ||
} | ||
</style> | ||
<title></title> | ||
</head> | ||
|
||
<body> | ||
<div id="header">Header</div> | ||
<div id="body">Body</div> | ||
<div id="footer">Footer</div> | ||
</body> | ||
|
||
</html> |