Reputation: 3254
I'm trying to create a pdf using itext but i'm getting an error on the line :
ItextRenderer renderer = new ITextRenderer();
The error is something like this :
05-20 12:00:48.468: E/AndroidRuntime(6121): java.lang.VerifyError: org/xhtmlrenderer/pdf/ITextOutputDevice
It create the file but the file is a bug (the size is 0kb and it's not openable)
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;
}
Upvotes: 4
Views: 1888
Reputation: 21547
I was also looking for an Android HTML to PDF converter and looked into Flying Saucer. I ran into the same issue, and noticed that Flying Saucer is not an Android Library, but a JAVA Library. It uses Java classes not available to Android (ex: java.awt.*), so the jar won't work on an Android device.
Upvotes: 2
Reputation: 175
Format your HTML properly , i also had same issue .. itext does not accepts unformatted HTML string, your pdf gets damaged..
Upvotes: 1