iText - HTML para PDF - A imagem não é exibida em PDF
Eu tenho uma página html com texto, imagem e estou analisando o conteúdo HTML para iText para gerar o PDF. No PDF gerado, as imagens incluídas não são exibidas e somente o texto é exibido.
Se eu passar o caminho absoluto comoD: /Deiva/CRs/HTMLPage/article-101-horz.jpg então a imagem será impressa. Mas se eu tentar imprimir a imagem do servidor como
http://localhost:8085/content/dam/article-101-h1.jpg or http://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif
então não está sendo impresso no PDF.
NOTA: estou usandoitextpdf-5.2.1.jar para gerar o PDF.
Meu código HTML (Article.html):
<html>
<head>
</head>
<body>
<p>Generate PDF with image using iText.</p>
<img src="http://localhost:8085/content/dam/article-10-h1.jpg"></img>
<img src="http://www.google.co.in/intl/en_ALL/images/logos/imgs_logo_lg.gif"></img>
<img class="right horz" src="D:/Deiva/CRs/HTMLPage/article-101-horz.jpg"></img>
</body>
</html>
Eu estou usando o código java abaixo para gerar o PDF:
private void createPDF (){
String path = "D:/Deiva/Test.pdf";
PdfWriter pdfWriter = null;
//create a new document
Document document = new Document();
try {
//get Instance of the PDFWriter
pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(path));
//document header attributes
document.addAuthor("betterThanZero");
document.addCreationDate();
document.addProducer();
document.addCreator("MySampleCode.com");
document.addTitle("Demo for iText XMLWorker");
document.setPageSize(PageSize.LETTER);
//open document
document.open();
InputStream is = new FileInputStream("D:/Deiva/CRs/Oncology/Phase5/CR1/HTMLPage/Article.html");
// create new input stream reader
InputStreamReader isr = new InputStreamReader(is);
//get the XMLWorkerHelper Instance
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
//convert to PDF
worker.parseXHtml(pdfWriter, document, isr);
//close the document
document.close();
//close the writer
pdfWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Por favor, sugira uma solução para exibir a imagem em PDF.
Desde já, obrigado.
Deiva