From 3babdf48a278faa18e1a47fd519709017186e6d1 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 24 Mar 2020 09:42:15 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-28589=20html=E8=A7=A3=E6=9E=90=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E8=A1=8C=E4=B8=8D=E5=BA=94=E8=AF=A5=E5=85=A8?= =?UTF-8?q?=E6=98=AF=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../text/html/simpleparser/HTMLWorker.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java index e8f3f1406..a3558dab3 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/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);