|
@@ -0,0 +1,36 @@
|
|
|
+package br.eti.mertz.wkhtmltopdf.wrapper;
|
|
|
+
|
|
|
+import org.apache.pdfbox.pdfparser.PDFParser;
|
|
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.apache.pdfbox.util.PDFTextStripper;
|
|
|
+import org.junit.Assert;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+
|
|
|
+import static org.hamcrest.core.StringContains.containsString;
|
|
|
+
|
|
|
+public class PdfTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testPdfFromStringTo() throws Exception {
|
|
|
+
|
|
|
+ // GIVEN a html template containing special characters that java stores in utf-16 internally
|
|
|
+ Pdf pdf = new Pdf();
|
|
|
+ pdf.addHtmlInput("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
|
|
|
+
|
|
|
+ // WHEN
|
|
|
+ byte[] pdfBytes = pdf.getPDF();
|
|
|
+
|
|
|
+ PDFParser parser = new PDFParser(new ByteArrayInputStream(pdfBytes));
|
|
|
+
|
|
|
+ // that is a valid PDF (otherwise an IOException occurs)
|
|
|
+ parser.parse();
|
|
|
+ PDFTextStripper pdfTextStripper = new PDFTextStripper();
|
|
|
+ String pdfText = pdfTextStripper.getText(new PDDocument(parser.getDocument()));
|
|
|
+
|
|
|
+ Assert.assertThat("document should contain the creditorName", pdfText, containsString("Müller"));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|