Free Support Forum - aspose.com

HTML img tag with absolute url does not render in converted PDF/RTF

Hi,

I have a simple HTML file with a public image referenced as an absolute url in the tag. Using the latest Aspose Words Java library (version 11.11), when converting this HTML to PDF/RTF, the image does not get displayed. Please note, that the img tag is referencing an image not by relative url (but by an absolute url). I have attached sample HTML file with the rendered output in PDF/RTF so you can reproduce on your end

Example



This is my image





FYI - In Java I’m converting from HTML to RTF using the following constructs:

Document doc= new Document(new FileInputStream(“C:/temp/TestImage.html”));
RtfSaveOptions saveOptions = new RtfSaveOptions();
doc.save(“C:/temp/TestImage.rtf”, saveOptions);

Hi Hiral,


Thanks for your inquiry.


Aspose.Words for Java conversion from HTML to RTF/PDF is working flawlessly here on our side. I was able to reproduce the issue but only when internet connectivity is not there on the development machine. Please make sure that while using absolute urls your internet is working fine when Aspose.Words for Java is processing your documents.


Hope this helps. Please let us know if you have any more queries.


Hi Muhammad,

I see the issue. The issue is that our application goes through a proxy in order to reach the internet. Is there something in the Aspose library in which I can set the proxy host and proxy port before converting the HTML to RTF/PDF so Aspose knows to use the proxy parameters when extracting images which are external?

Thanks

Hi Hiral,


Thanks for your patience.


Sorry but after looking thoroughly into the issue, I can say that there is no such thing in the API to set the proxy host and proxy port. You can use LoadOptions while opening Document and specify the content type to be loaded as com.aspose.words.LoadFormat.HTML into the Document.


Furthermore, you can also implement IResourceLoadingCallback interface in your class and ensure loading of document's resources in it using any logic in native java. In callback method, you can use any logic to connect to the internet either with or without proxy. You can use any custom class to handle proxy server on your end or can also use some Java SDK solution to connect to internet from behind the proxy, get the image data and set it in the callback's ResourceLoadingArgs object so that it should be included in the final document. For further details, you can also look here for documentation reference to LoadOptions and setting up callback.


To start with, you can use java.net.Proxy class to open a connection via proxy and load resource data as a stream in IResourceLoadingCallback resourceLoading(ResourceLoadingArgs) method. Another viable option could be to set the JVM flags "http.proxyHost" and "http.proxyPort" as suggested here. You can also go through the Java documentation here to find further details.


Attached are the output documents in RTF and PDF format produced during the testing and conversion is working very well on our side.


Hope this helps. Please let us know if you have any more queries.