Browse Source

REPORT-28589 html解析最后一行不应该全是空格

release/10.0
Hugh.C 5 years ago
parent
commit
3babdf48a2
  1. 15
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java

15
fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java

@ -171,6 +171,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
worker.setInterfaceProps(interfaceProps);
worker.objectList = new ArrayList();
worker.parse(reader);
return worker.objectList;
}
@ -178,7 +179,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
try {
for (int k = 0; k < stack.size(); ++k)
document.add((Element) stack.elementAt(k));
if (currentParagraph != null)
if (needAddLastParagraph())
document.add(currentParagraph);
currentParagraph = null;
} catch (Exception e) {
@ -186,6 +187,18 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
}
}
private boolean needAddLastParagraph() {
if (currentParagraph == null) {
return false;
}
ArrayList list = currentParagraph.getChunks();
if (!(list.size() == 1 && list.get(0) instanceof Chunk)) {
return true;
}
Chunk c = (Chunk) list.get(0);
return c.getImage() != null || c.getContent().trim().length() != 0;
}
public void startDocument() {
HashMap h = new HashMap();
style.applyStyle("body", h);

Loading…
Cancel
Save