Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,29 @@ private PDDocument createDocument(String title, PDFont font, String text) throws
void testEscapeTitle() throws IOException
{
PDFTextStripper stripper = new PDFText2HTML();
PDDocument doc = createDocument("<script>\u3042", new PDType1Font(FontName.HELVETICA),
"<foo>");
String text = stripper.getText(doc);

Matcher m = Pattern.compile("<title>(.*?)</title>").matcher(text);
assertTrue(m.find());
assertEquals("&lt;script&gt;&#12354;", m.group(1));
assertTrue(text.contains("&lt;foo&gt;"));
try(PDDocument doc = createDocument("<script>\u3042", new PDType1Font(FontName.HELVETICA),
"<foo>"))
{
String text = stripper.getText(doc);

Matcher m = Pattern.compile("<title>(.*?)</title>").matcher(text);
assertTrue(m.find());
assertEquals("&lt;script&gt;&#12354;", m.group(1));
assertTrue(text.contains("&lt;foo&gt;"));
}
}

@Test
void testStyle() throws IOException
{
PDFTextStripper stripper = new PDFText2HTML();
PDDocument doc = createDocument("t", new PDType1Font(FontName.HELVETICA_BOLD), "<bold>");
String text = stripper.getText(doc);
try(PDDocument doc = createDocument("t", new PDType1Font(FontName.HELVETICA_BOLD), "<bold>"))
{
String text = stripper.getText(doc);

Matcher bodyMatcher = Pattern.compile("<p>(.*?)</p>").matcher(text);
assertTrue(bodyMatcher.find(), "body p exists");
assertEquals("<b>&lt;bold&gt;</b>", bodyMatcher.group(1), "body p");
Matcher bodyMatcher = Pattern.compile("<p>(.*?)</p>").matcher(text);
assertTrue(bodyMatcher.find(), "body p exists");
assertEquals("<b>&lt;bold&gt;</b>", bodyMatcher.group(1), "body p");
}
}
}