diff --git a/pdf-html/src/test/java/com/lowagie/text/html/HtmlParserTest.java b/pdf-html/src/test/java/com/lowagie/text/html/HtmlParserTest.java
new file mode 100644
index 000000000..462897ace
--- /dev/null
+++ b/pdf-html/src/test/java/com/lowagie/text/html/HtmlParserTest.java
@@ -0,0 +1,38 @@
+package com.lowagie.text.html;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.StringReader;
+
+import org.junit.Test;
+
+import com.lowagie.text.Document;
+import com.lowagie.text.TextElementArray;
+
+public class HtmlParserTest {
+
+ /**
+ * Bug fix scenario: a table with a space throws a {@link TextElementArray}
+ * class cast Exception. A table without spaces is parsed correctly.
+ */
+ @Test
+ public void testParse_tableWithNoSpaces() {
+ Document doc1 = new Document();
+ doc1.open();
+ HtmlParser.parse(doc1, new StringReader("
")); // succeeds
+ assertNotNull(doc1);
+ }
+
+ /**
+ * Bug fix scenario: a table with a space throws a {@link TextElementArray}
+ * class cast Exception.
+ */
+ @Test
+ public void testParse_tableWithSpaces() {
+ Document doc1 = new Document();
+ doc1.open();
+ HtmlParser.parse(doc1, new StringReader("")); // fails
+ assertNotNull(doc1);
+ }
+
+}
diff --git a/pdf-xml/src/main/java/com/lowagie/text/xml/SAXiTextHandler.java b/pdf-xml/src/main/java/com/lowagie/text/xml/SAXiTextHandler.java
index 8f638b2dc..ce0d4c1dc 100644
--- a/pdf-xml/src/main/java/com/lowagie/text/xml/SAXiTextHandler.java
+++ b/pdf-xml/src/main/java/com/lowagie/text/xml/SAXiTextHandler.java
@@ -206,6 +206,10 @@ public void startElement(String uri, String lname, String name,
handleStartingTags(name, attributes);
}
+ private boolean isNotBlank(String text) {
+ return text != null && !text.trim().isEmpty();
+ }
+
/**
* This method deals with the starting tags.
*
@@ -223,7 +227,7 @@ public void handleStartingTags(String name, Properties attributes) {
}
// maybe there is some meaningful data that wasn't between tags
- if (currentChunk != null) {
+ if (currentChunk != null && isNotBlank(currentChunk.getContent())) {
TextElementArray current;
try {
current = (TextElementArray) stack.pop();