Skip to content

Commit

Permalink
#79 - Testcase runner for PDF/UA tests and first simple testcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfickle committed Jan 12, 2019
1 parent a145329 commit c986c70
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
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");
}
}
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>

0 comments on commit c986c70

Please sign in to comment.