2016-02-16 82 views
0

使用飛碟在PDF中打印圖像。使用飛碟在PDF中打印圖像

HTML代碼:

<?xml version="1.0" encoding="utf-8" ?> 
<html> 
    <p> 
     <img src="Smallcheck.jpg" width="20" height="21"/> 
    </p> 
</html> 

當我用飛碟HTML轉換爲PDF。生成的PDF不打印圖像。

var outputForPdfStream = new this.ByteArrayOutputStream(); 

// tidy the html 
var domdoc = this.domDocument; 
var iTidy = new this.tidy(); 
iTidy.setShowWarnings(false); 
iTidy.setXmlTags(false); 
iTidy.setInputEncoding("UTF-8"); 
iTidy.setOutputEncoding("UTF-8"); 
iTidy.setXHTML(true);// 
iTidy.setMakeClean(true); 
domdoc = iTidy.parseDOM(inputStream, outputForPdfStream); 

// Convert the document to XHTML panel and then rendering it into a PDF 
var xhtmlPanel = new this.XHTMLPanel(); 
xhtmlPanel.setDocument(domdoc); 

var renderer = new this.iTextRenderer(); 
renderer.setDocument(xhtmlPanel.getDocument(), null); 
renderer.layout(); 
renderer.createPDF(bos); 
bos.flush(); 
inputStream.close(); 
this.debug("INPUT STREAM" + inputStream); 

var byteArray = bos.toByteArray(); 
var encodedString = this.StringUtil.base64Encode(byteArray); 
this.debug("Encoded String" + encodedString); 

是否需要使用任何特定包以PDF格式打印圖像。請讓我知道,如果你有任何問題。

回答

0

您需要爲您的圖像的背景和相對路徑,

renderer.setDocument(xhtmlPanel.getDocument(), null); 

應該改變,

renderer.setDocument(xhtmlPanel.getDocument(), "http:\\mywebsite:8080\images"); 

而且你的圖片應該是在上下文中指定的文件夾下,你可以使用src中你的圖片的相對路徑,

<?xml version="1.0" encoding="utf-8" ?> 
<html> 
    <p> 
     <img src="check/Smallcheck.jpg" width="20" height="21"/> 
    </p> 
</html>