Convert to PDF a HTML page with an image data URI element

738 views
Skip to first unread message

donal....@cognovi.ie

unread,
May 22, 2017, 12:25:11 PM5/22/17
to Flying Saucer Users
Hi,

I've been trying to convert a HTML document such as the following to a PDF

<!DOCTYPE html>
<html>
<head>
</head>
<body>
 
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAADICAYAAAAQj4UaA....(truncated)">
 
<p>SOME TEXT</p>
</body>
</html>

The code I'm using to convert it to a PDF is:

ITextRenderer renderer = new ITextRenderer();
renderer
.documentFromString = htmlString;
renderer
.layout();
renderer
.createPDF(fileOutputStream, false);
renderer
.finishPDF();

The generated PDF does not include the image, so I guess either I'm not generating the PDF correctly, or these kinds of images are not supported? 

I'm using version 9.1.5, and I can see that support for base-64 encoded images does exist in this version, when the image data is provided via the "background-image" CSS property. So perhaps it's the case that I need to use this CSS property instead of the "src" HTML attribute?

Thanks in advance,
Donal




Reply all
Reply to author
Forward
0 new messages