Hello,
We try to convert an HTML/URL to an image using Aspose.HTML with Java and we can’t since the documentation seems not to be updated.
Indeed, it misses some classes in last version of Aspose.HTML 20.8
We also made others tests with Aspose.Words to make the conversion but the quality of the image is not what we expect.
To be more precise, we try to convert an HTML or an URL to an image
For this, we have tested :
1 - Using Aspose.HTML to convert HTML to Image (PNG)
→ Convert PDF to Images formats|Aspose.PDF for Java
2 - To convert from URL to PDF and then to image using Aspose.PDF
→ Convert HTML to PDF file in Java|Aspose.PDF for Java
→ Convert PDF to Images formats|Aspose.PDF for Java
3 - To convert from URL to image using Aspose.Words
→ From Url to Image with Aspose in Java - Stack Overflow
4 - To convert from a HTML file to image using Aspose.Words
Nothing of thus solutions are satisfying.
Can you help us using your tool please with an exemple of code in Java?
For exemple, can we test with this URL https:// www.lemonde. fr/economie-mondiale/
Thanks in advance
@HamidOppHoney
Would you kindly point out the Classes Names which you found missing in the latest version of the API. Also, we would like to share with you that Aspose.HTML is specialized to deal with HTML files and we would recommend you use it in case you only want to deal with them.
Furthermore, we request you to please generate a separate ticket in Aspose.PDF or Aspose.Words forum categories for the respective APIs so that they can be addressed accordingly.
Hello,
First i can’t get Aspose.HTML 20.8.
When i downgrade to version 20.6 it’s ok but there’s no package “com.aspose.html.converters” and no class com.aspose.html.saving.ImageSaveOptions
Here is a snippet of my pom.xml :
<aspose.version>20.8</aspose.version>
<repositories>
<repository>
<id>aspose</id>
<name>Aspose java api</name>
<url>https://artifact.aspose.com/repo/</url>
</repository>
<repository>
<id>snapshots</id>
<name>repo</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-html</artifactId>
<version>${aspose.version}</version>
</dependency>
</dependencies>
I use this page for my exemple :
@HamidOppHoney
We have changed the product version to match other products. It is now referred to as
compile “com.aspose: aspose-html: 20.8: jdk16”. A classifier has been added i.e. jdk16.
Please update your pom.xml file as following:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-html</artifactId>
<version>20.8</version>
<classifier>jdk16</classifier>
</dependency>
Hello,
It seems to work. Thanks !!!
Please update the documentation for others :
Can you tell us if it’s possible to convert :
- from an URL file to Image, Text or HTML ?
@HamidOppHoney
We have updated the documentation as well.
Please check following article(s) in API documentation for conversion of HTML into different file formats:
You can initialize HTMLDocument with any address e.g. URL:
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("http://www.aspose.com");
Hello,
Thanks for your last answer.
Even if the solution that you show me, it doesn’t work.
When i try to convert an url (aspose.com) to image i have multiple images with nothing in it (some vertical lines only)
Can you show me a full exemple in Java to convert an url to a single “good” image please?
By the way, can we tell us how to create an HTMLDocument object from an inputStream
Is it mandatory to pass a BaseURI ???
Thanks in advance.
Moreover, it can’t work with websites like https://www.20minutes.fr/
Is-it a problem related to HTTPS?
Thanks.
@HamidOppHoney
You can initialize HTMLDocument object with a URL, File Path as well as inputStream. Please check all supported constructor values in the following link. Furthermore, it is not mandatory to pass BaseURI.
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("https://www.aspose.com");
try {
// Initialize ImageSaveOptions
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Png);
// Convert HTML to PNG
com.aspose.html.converters.Converter.convertHTML(document, options, dataDir + "output.png");
} finally {
if (document != null) {
document.dispose();
}
}
Above code snippet can be used to convert HTML into an image. We have tested the scenario in our environment while converting an URL into image and faced similar issue which you have mentioned. Therefore, have logged it as HTMLJAVA-567 in our issue tracking system. We will further look into its details and inform you as soon as it is resolved. Please be patient and spare us some time.
We are sorry for the inconvenience caused.