Diego Celery
Diego Celery

Reputation: 21

iTextPDF 7 (7.1.5), pdfHTML add-on. HTML to PDF. URL images not in PDF output

I have a html page with text, images and I am converting HTML to PDF. In the generated PDF, included images are not getting displayed and , only the text and base64 embedded images are getting displayed. URL images not.

If I pass a baseURI ConverterProperty like "D:/HTML/images/", change the HTML(XSLT) images URL deleting "http://" from URL and make de URL Path as folder into de base URI folder, the proccess works fine!!!

Example code:

ConverterProperties props = new ConverterProperties();
props.setBaseUri("D:/HTML/images/");
HtmlConverter.convertToPdf(htmlString, dest,props);

Having html img tag with src attribute value:

http://www.mywebserver.com/gsi/img/logo.jpg

Changed to:

www.mywebserver.com/gsi/img/logo.jpg

Saving the image to:

D:/HTML/images/www.mywebserver.com/gsi/img/logo.jpg

It works fine!!!

But if i try images from the server like:

http://www.mywebserver.com/gsi/img/Logo.jpg

then the image it is not in the PDF output.

NOTE: I am using itextpdf 7.1.5 to generate the PDF.

My simple code:

HtmlConverter.convertToPdf(htmlString, dest);

My server log:

mar 15, 2019 11:18:27 AM com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver retrieveImageExtended
GRAVE: Unable to retrieve image with given base URI (file:/D:/wlsservermydomain/) and image source path (http://www.mywebserver.com/gsi/img/Logo.jpg)
<15-03-2019 11:18:27 Hora de Chile> <Error> <com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver> <BEA-000000> <Unable to retrieve image with given base URI (file:/D:/wlsservermydomain/) and image source path (http://www.mywebserver.com/gsi/img/Logo.jpg)>
mar 15, 2019 11:18:27 AM com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor visit
GRAVE: Worker of type com.itextpdf.html2pdf.attach.impl.tags.TdTagWorker unable to process com.itextpdf.html2pdf.attach.impl.tags.ImgTagWorker
<15-03-2019 11:18:27 Hora de Chile> <Error> <com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor> <BEA-000000> <Worker of type com.itextpdf.html2pdf.attach.impl.tags.TdTagWorker unable to process com.itextpdf.html2pdf.attach.impl.tags.ImgTagWorker>

It seems that iTextPDF is looking for the images in the server's working folder D:\wlsservermydomain.

How do I get iText to look for the images online?

Thanks!

Upvotes: 1

Views: 3952

Answers (1)

rohit prakash
rohit prakash

Reputation: 575

Server from which you are using image is restricting to download image without Browser User-Agent, that's why in pdf no image is included.

Try with different image url, where server allowing download without user-agent also

For example:

https://images.homedepot-static.com/productImages/e0b36c9f-48c2-4fbd-ace8-3fa0e877aacc/svn/york-wallcoverings-wallpaper-at7053-64_1000.jpg

you will get image in your pdf.

Internally itext using url.openStream()) to get input stream from import java.net.URL;

Upvotes: 0

Related Questions