0

While downloading a file I am getting the error:

The entity “nbsp” was referenced, but not declared.

I am able to download the file but I am not able to preview the file. Below is my snippet:

is = new ByteArrayInputStream(articleHtml.getBytes());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(is, null);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);
renderer.layout();
try {
    renderer.createPDF(outputStream);
} catch (com.lowagie.text.DocumentException e) {
    e.printStackTrace();
}

I have tried with replacing the   with  . Please help me to solve this problem.

TT.
  • 15,774
  • 6
  • 47
  • 88
Pradnya
  • 1
  • 1
  • 4
  • As this is about the data in your document: Create a minimal article that can be used to reproduce. Inspect the article that you currently have and strip it of anything unimportant, until just the problem stays. From the naming of your variable it looks like it's HTML. Add that text to your question. – Olaf Kock Nov 03 '17 at 08:49

1 Answers1

0

Have you tried declaring entity as error says?

<!DOCTYPE test [
  <!ENTITY nbsp "&#160;">
]>
<test>The Spanish word for "Spain" is "Espa&nbsp;a" Dagon his Name, Sea Monster</test>

Taken from The entity "nbsp" was referenced, but not declared

Klimiuk S
  • 354
  • 1
  • 9
  • Yes.. i tried putting this in the template, but I am getting the exception like this org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 37; A DOCTYPE is not allowed in content. – Pradnya Nov 03 '17 at 06:16
  • 1
    Please, edit your question with sample article that causes error. – Klimiuk S Nov 03 '17 at 09:29