I am working with iTextPdf (iTextG for Android) to convert an Html document to PDF for my Android application. Everything works fine for me, except for the logo on the receipt. My html contains a tag <img>
with the source url for the image
<img src="http...."></img>
created pdf has no image. The same code and html running in my Java application show the logo with the created PDF (this shows that there is no problem accessing the image). I am wondering if this feature is compatible with Java, but not with Android? I use the following dependencies:
compile 'com.itextpdf:itextg:5.5.10'
compile 'com.itextpdf.tool:xmlworker:5.5.10'
HTML code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="English">
<head>
<title>Title</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<img src="https://image.flaticon.com/teams/slug/google.jpg"></img>
<h1>Fischerstube</h1>
</body>
</html>
Function in core business:
private void htmlToPdf(String html) throws DocumentException, IOException {
try {
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "logo.pdf");
OutputStream fileOutputStream = new FileOutputStream(file);
Document document = new Document();
document.setPageSize(new Rectangle(201,720));
PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
document.open();
InputStream is = new ByteArrayInputStream(html.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
document.close();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
The only rendering tag <h1>
and shows Fischerstube, but without an image on ANDROIRD DEVICE. Can anyone help me in this regard, we will be grateful.