-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#79 - Testcase runner for PDF/UA tests and first simple testcase.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...mltopdf-examples/src/main/java/com/openhtmltopdf/testcases/pdfua/PdfUaTestcaseRunner.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,44 @@ | ||
package com.openhtmltopdf.testcases.pdfua; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.pdfbox.io.IOUtils; | ||
|
||
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder; | ||
import com.openhtmltopdf.visualregressiontests.TextVisualRegressionTest; | ||
|
||
public class PdfUaTestcaseRunner { | ||
private static void run(String testCase) throws Exception { | ||
byte[] htmlBytes = IOUtils | ||
.toByteArray(PdfUaTestcaseRunner.class.getResourceAsStream("/testcases/pdfua/" + testCase + ".html")); | ||
String html = new String(htmlBytes, StandardCharsets.UTF_8); | ||
|
||
new File("./target/pdfua-test-cases/").mkdirs(); | ||
|
||
if (!(new File("target/test/visual-tests/Karla-Bold.ttf")).exists()) { | ||
try (InputStream in = TextVisualRegressionTest.class.getResourceAsStream("/visualtest/html/fonts/Karla-Bold.ttf"); | ||
OutputStream out = new FileOutputStream("target/test/visual-tests/Karla-Bold.ttf")) { | ||
IOUtils.copy(in, out); | ||
} | ||
} | ||
|
||
try (FileOutputStream os = new FileOutputStream("./target/pdfua-test-cases/" + testCase + ".pdf")) { | ||
PdfRendererBuilder builder = new PdfRendererBuilder(); | ||
builder.testMode(true); | ||
builder.usePdfUaAccessbility(true); | ||
builder.useFont(new File("target/test/visual-tests/Karla-Bold.ttf"), "TestFont"); | ||
builder.withHtmlContent(html, PdfUaTestcaseRunner.class.getResource("/testcases/pdfua/").toString()); | ||
builder.toStream(os); | ||
builder.run(); | ||
} | ||
|
||
} | ||
|
||
public static void main(String... args) throws Exception { | ||
run("simple"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
openhtmltopdf-examples/src/main/resources/testcases/pdfua/simple.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,23 @@ | ||
<html> | ||
<head> | ||
<title>Simple PDF/UA Testcase</title> | ||
<meta name="description" content="A simple example"/> | ||
<style> | ||
@page { | ||
size: 200px 200px; | ||
margin: 0; | ||
} | ||
body { | ||
margin: 0; | ||
width: 200px; | ||
} | ||
</style> | ||
</head> | ||
<body style="font-family: 'TestFont'; font-size: 14px;"> | ||
<p>Paragraph one. Some text that goes over multiple lines. OK, this is getting to the required length.</p> | ||
|
||
<p>Paragraph two. Some text that goes over multiple lines. OK, this is getting to the required length.</p> | ||
|
||
<p>Paragraph three. Some text that goes over multiple lines. OK, this is getting to the required length.</p> | ||
</body> | ||
</html> |