簡體   English   中英

從HTML到PDF的圖像轉換

[英]HTML to PDF conversion with images

我在將HTML結構中的圖像解析為PDF文件時遇到問題,我嘗試使用以下行來收集圖像,但是在創建PDF文件時沒有圖像。 我將iText與xmlworker庫一起使用,html全部存儲在字符串中,然后解析為輸入流,如下代碼所示。

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

您可能應該使用自己的ImageProvider來獲取圖像。 http://api.itextpdf.com/xml/com/itextpdf/tool/xml/pipeline/html/ImageProvider.html

該接口有4種方法:

  • getImageRootPath()
  • 重啟()
  • 檢索(字符串src)
  • store(String src,圖片img)

您將需要實現檢索方法,以從文件系統返回圖像。

有關XMLWorker的文檔: http ://demo.itextsupport.com/xmlworker/itextdoc/flatsite.html#itextdoc-menu-10

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM