I am using java and iText 5 to produce a PDF. One of my input lines is from a WYSIWYG editor containing html with a base64 image imbedded (i.e., not the link to the image). The WYSIWYG can have zero to many images.
WYSIWYG contains:
This "Description" is processed by my code:
Document document = new Document(PageSize.A4, 72f, 72f, 72f, 72f);
PdfWriter.getInstance(document, resourceImage);
document.open();
String ppDescription = "";
if(activityDtl.getPPDescription() == null || activityDtl.getPPDescription().isEmpty()){
ppDescription = "";
}else{
//Clean the HTML to be correct XHTML
String cleanDesc = cleanHTML(activityDtl.getPPDescription());
InputStream inputStream1 = new ByteArrayInputStream (cleanDesc.getBytes("UTF-8"));
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
Tidy tidy1 = new Tidy();
tidy1.setXHTML(true);
tidy1.setQuiet(true);
tidy1.setShowWarnings(false);
tidy1.parseDOM(inputStream1, baos1);
ppDescription = baos1.toString();
// System.out.println("ppDescription: " + ppDescription);
}
p6.add(new Chunk("Description: ", smallBold));
if(ppDescription == null || ppDescription.isEmpty()){
p6.add("");
}else{
ElementList list1 = XMLWorkerHelper.parseToElementList(ppDescription, null);
System.out.println("list1: " + list1);
for (Element element : list1) {
p6.add(element);
}
}
cell.addElement(p6);
This is what is received in the input for this field (Description) is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator"
content="HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net" />
<title></title>
</head>
<body>
<p>Cooking instructions:</p>
<p><img
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAggAAAC .... H3BNquwQYUAAAAASUVORK5CYII="
alt="" /></p>
<p>Cook the fish.</p>
</body>
</html>
And this is what is in the PDF:
What I would like is to have in the PDF the same as the first image in the WYSIWYG (i.e., the image between the two instruction lines).