HTML is frequently used to display data and information over web pages, web applications, and different platforms. You may need to convert HTML to an image like JPG, PNG, TIFF, BMP, etc. You can perform the HTML to image conversion programmatically using Aspose.HTML for Java in your Java-based applications. Moreover, the API takes care of rendering HTML to image and you do not need to worry about underlying details of the file formats. Simply use the API calls and the HTML file will be rendered nicely. Let us explore Java HTML to image conversion in detail:
- HTML to Image Converter – API Installation
- Convert HTML to JPG Image
- Convert HTML to PNG Image
- Converting HTML to TIFF Image
- Convert HTML to BMP Image
Java HTML to Image Converter – API Installation
Aspose.HTML for Java API supports editing, manipulating as well as converting HTML files using Java language. It can easily be configured by downloading from New Releases or via Aspose Repository with the following installation configurations:
Repository
<repositories>
<repository>
<id>snapshots</id>
<name>repo</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
</repositories>
Dependency
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-html</artifactId>
<version>20.12</version>
<classifier>jdk16</classifier>
</dependency>
</dependencies>
Convert HTML to JPG Image in Java
You can easily convert HTML files to image with few lines of code. Let us learn HTML to JPG image conversion with the steps below:
- Load input HTML file
- Initialize ImageSaveOptions
- Convert HTML to output JPG image
The code snippet below shows how to convert HTML to JPG image using Java code:
Convert HTML to PNG Image using Java
PNG image format is another popular image type which is often preferred because of some image features. For example, a PNG image supports transparency in the picture. You can render a HTML file to PNG image with these steps:
- Load input HTML file with HTMLDocument class
- Specify ImageFormat as PNG
- Save output PNG image
The following code explains how to convert HTML to PNG image:
Converting HTML to TIFF Image in Java
TIFF image file format is popular because of wide support in almost all system environments. You can easily convert HTML to TIFF images with few simple steps:
- Initialize HTMLDocument to load input HTML
- Specify ImageFormat.Tiff for the output format
- Save output TIFF image
The code below elaborates how to convert HTML to TIFF image in Java language:
Convert HTML to BMP Image using Java
Exploring several other methods and properties for HTML to Image conversion, let us explore setting the page size, background color, etc. for the output file. You can easily convert HTML to BMP image with these additional options, using the following steps:
- Load input HTML file
- Specify size and background color for the output image
- Save output TIFF image
The code below demonstrates how to convert HTML file to TIFF image using Java:
Info: Using Aspose JPG to PPT or PNG to PPT converter, you can generate PowerPoint presentations from simple images.
Conclusion
We have learned how to convert or render HTML files to different image formats including JPG, PNG, TIFF, BMP, etc using Java. You can further explore the efficiency and features of the API by checking through the examples project. It showcases a lot of features for working with HTML files. In addition, you can always reach out to us at Free Support Forum to discuss any of your requirements or concerns.