Convert HTML to JPG Images in Java using GroupDocs.Conversion Cloud REST API

Convert HTML to JPG Image in Java using REST API

HTML (HyperText Markup Language) is a standard markup language used to create web pages. It allows developers to structure web content, including text, images, links, and multimedia elements. On the other hand, JPG is a popular image format that is used for storing and sharing digital photos. Converting HTML files to JPG images has become very important, such as when you need to share an HTML report and store HTML content as a backup. In this article, we’ll discuss how to convert HTML to JPG images in Java using REST API.

The following topics will be covered in this tutorial:

Java HTML to Image Conversion REST API and Java SDK Installation

We are going to use GroupDocs.Conversion Cloud SDK for Java to convert HTML documents into JPG images. GroupDocs.Cloud API is a powerful tool for converting multiple types of documents and images, including HTML to JPG files. This API offers a wide range of file formats, enabling you to convert HTML, PDFs, Word documents, Excel sheets, CAD files, and raster images, among others. Integrating the API into Java-based applications is made simple and efficient, eliminating the need for additional software.

You can either download the API’s JAR file or install it using Maven by adding the following repository and dependency into your project’s pom.xml file:

Maven Repository:

<repository>
    <id>groupdocs-artifact-repository</id>
    <name>GroupDocs Artifact Repository</name>
    <url>https://repository.groupdocs.cloud/repo</url>
</repository>

Maven Dependency:

 <dependency>
    <groupId>com.groupdocs</groupId
    <artifactId>groupdocs-conversion-cloud</artifactId>
    <version>23.4</version>
    <scope>compile</scope>
</dependency>

Sign up for a GroupDocs account to obtain the application ID and application Secret from the dashboard before you start following the steps and available code snippets. Please enter the code snippet shown below once you have your ID and Secret:

Convert HTML Files to JPG Format Online in Java using REST API

The process of converting HTML to JPG images in Java with GroupDocs.Conversion Cloud SDK for Java REST API is straightforward and simple. Here are the steps to follow:

Upload the File

Firstly, upload the HTML document to the cloud storage using the code snippet given below:

As a result, the uploaded HTML document will be available in the files section of your dashboard on the cloud.

Convert HTML to JPG Images in Java

In this section, we will write the code snippet that automates the HTML to JPG conversion process in a Java application. You may follow the steps and the code snippet mentioned below:

  • Firstly, import the required classes into your Java file.
  • Secondly, create an instance of ConvertApi class.
  • Thirdly, create an instance of the ConvertSettings class.
  • After that, provide the cloud storage name.
  • Next, set the input HTML file path and the output file format to “jpg”.
  • Now, create an instance of the JpgConvertOptions class.
  • Optionally, provide various convert options like setFromPage, setPagesCount, setGrayscale, setHeight, setQuality, setRotateAngle, setUsePdf, etc.
  • Then, set convert options and the output file path using ConvertSettings instance.
  • Then, create a ConvertDocumentRequest class instance and pass settings parameter.
  • Finally, call the convertDocument() method and pass ConvertDocumentRequest parameter.

The following code snippet shows how to convert an HTML document to JPG image programmatically in Java using REST API:

Java convert HTML documents to JPG images

Convert HTML documents to JPG images in Java.

Download the Converted File

The above code sample will save the converted JPG image to the cloud. You can download the converted JPG file using the following code snippet:

Free Online HTML to JPG Converter

How to convert HTML to JPG images online for free? Please try an online HTML to JPG converter to create a JPG image from an HTML document. This converter is developed using the above-mentioned HTML to JPG image REST API.

Summing up

This brings us to the end of this blog post. The following is what you have learned from this article:

  • how to convert HTML to JPG image in Java programmatically, as well as additional customization options;
  • programmatically upload the HTML document to the cloud and then download the converted JPG image from the cloud;
  • and convert any HTML web page to JPG for free using a free online HTML to JPG image converter.

Moreover, we also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser. Java SDK’s complete source code is freely available on Github. Please check the GroupDocs.Conversion Cloud SDK for Java Examples here.

Additionally, we suggest you follow our Getting Started guide for detailed steps and API usage.

Finally, we keep writing new blog articles on different file formats and conversions using REST API. So, please get in touch for latest updates.

Ask a question

If you have any questions regarding HTML to images conversion API, please do not hesitate to contact us on the free support forum.

FAQs

How do I convert HTML to JPG images using Java?

You can convert an HTML document to a JPG image in Java by using GroupDocs.Conversion Cloud REST API. It is a cloud-based document conversion API that allows developers to easily convert HTML documents to images in Java.

How can I convert an HTML file to JPG online for free?

HTML to JPG online converter allows you to convert HTML documents to JPG images for free. Once the online conversion of the HTML to JPG image is completed, you can instantly download the converted JPG files to your system. Please follow the step-by-step instructions given below to perform the conversion:

  • Open free HTML to JPG converter online.
  • Now, click in the file drop area to upload an HTML document or drag & drop an HTML file.
  • Next, click on the Convert Now button. Free online HTML to JPG converter will transform HTML files into JPG images.
  • The download link of the output JPG image will be available after converting the HTML web page.

Is there a way to convert HTML to images on Windows?

Please visit this link to download an offline HTML to images converter for Windows. This free HTML to images converter can quickly convert HTML documents to images on Windows with a single click.

See Also

If you want to learn more about related topics, we recommend reading the articles listed below: