我正在尝试使用 itext 创建一个 pdf,但在线上出现错误:
ItextRenderer renderer = new ITextRenderer();
错误是这样的:
05-20 12:00:48.468: E/AndroidRuntime(6121): java.lang.VerifyError: org/xhtmlrenderer/pdf/ITextOutputDevice
它创建文件,但文件是一个错误(大小为 0kb,无法打开)
private void HTMLtoPDF(){
try{
String outputFile = "sdcard/firstdoc.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(getHtmlBuffer().toString());
renderer.layout();
renderer.createPDF(os);
renderer.finishPDF();
os.close();
}catch (Exception e) {
e.printStackTrace();
}
}
private StringBuffer getHtmlBuffer() {
StringBuffer buff = new StringBuffer();
buff.append("<html xmlns='http://www.w3.org/1999/xhtml'>");
buff.append("<body>");
buff.append("<h2 style='color: #353535;font-size: 16px;margin: 0px;padding: 20px 0px;font-weight: bold;'>Test</h2>");
buff.append("<div id='news-details' class='news-details'>");
buff.append("<div class='news-details-data'>");
buff.append("some japanes charactors");
buff.append("</div></div>");
buff.append("</body></html>");
return buff;
}