1

I am having an issue to parse an image within HTML structure to a PDF file, I have tried using the following line to gather the image , however the PDF file is being created without the image. I am using iText with xmlworker libraries, the html is all stored in a string then parsed into an input stream as shown below in code.

.....
<img class='top' src='file:///android_res/drawable/logo.png' height='100px' width='200px'/>
........
........
InputStream is = new ByteArrayInputStream(str.getBytes()); //contains the html string
XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
4

1 回答 1

2

您可能应该使用自己的 ImageProvider 来获取图像。( http://api.itextpdf.com/xml/com/itextpdf/tool/xml/pipeline/html/ImageProvider.html )

这个接口有4个方法:

  • 获取图像根路径()
  • 重置()
  • 检索(字符串源)
  • 存储(字符串 src,图像 img)

您需要实现检索方法以从文件系统返回图像。

XMLWorker 文档:http: //demo.itextsupport.com/xmlworker/itextdoc/flatsite.html#itextdoc-menu-10

于 2015-02-19T08:28:00.270 回答