kabuto178
kabuto178

Reputation: 3167

HTML to PDF conversion with images

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);

Upvotes: 1

Views: 1539

Answers (1)

Micha&#235;l Demey
Micha&#235;l Demey

Reputation: 1577

You should probably use your own ImageProvider to fetch the images. (http://api.itextpdf.com/xml/com/itextpdf/tool/xml/pipeline/html/ImageProvider.html)

This interface has 4 methods:

  • getImageRootPath()
  • reset()
  • retrieve(String src)
  • store(String src, Image img)

You'll need to implement the retrieve method to return the Image from your file system.

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

Upvotes: 2

Related Questions