Hi All,
I am having an html page with text, image and I am parsing the HTML content to
iText to generate the PDF. In the PDF, image is not getting displayed, only the
text is getting displayed.
If I pass the absolute path like D:/Deiva/CRs/HTMLPage/article-101-horz.jpg
then the image will get printed. But if I try to print the image from the
server like
http://localhost:8085/content/dam/article-101-h1.jpg or
http://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif then it is
not getting printed in the PDF.
I am using itextpdf-5.2.1.jar to generate the PDF.
My HTML Code (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> <!--
Not Working -->
<img
src="http://www.google.co.in/intl/en_ALL/images/logos/imgs_logo_lg.gif"></img>
<!-- Not Working -->
<img class="right horz"
src="D:/Deiva/CRs/HTMLPage/article-101-horz.jpg"></img> <!-- Working -->
</body>
</html>
I am using the below java code for generating the 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();
}
}
Please suggest a solution to display the image (from the server) in PDF.
Thanks in advance.
Deiva
**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are
not
to copy, disclose, or distribute this e-mail or its contents to any other
person and
any such actions are unlawful. This e-mail may contain viruses. Infosys has
taken
every reasonable precaution to minimize this risk, but is not liable for any
damage
you may sustain as a result of any virus in this e-mail. You should carry out
your
own virus checks before opening the e-mail or attachment. Infosys reserves the
right to monitor and review the content of all messages sent to or from this
e-mail
address. Messages sent to or from this e-mail address may be stored on the
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php