pdf to html converter

Develop PDF to HTML converter with Java REST API.

Converting PDF documents to HTML format is essential for web development, content management, and improving accessibility. Whether you need to display documents online or repurpose content for web-based applications, converting PDF to HTML using Java REST API provides a simple and efficient solution. In this article, we will explore the step-by-step process of transforming PDF files into HTML format using GroupDocs.Conversion Cloud SDK for Java.

This article covers the following topics:

REST API for PDF to HTML Conversion

GroupDocs.Conversion Cloud SDK for Java offers a robust and flexible solution for converting PDF documents to HTML format with high accuracy. The API preserves document structure, images, and formatting while allowing customization of page range, output structure, and image quality.

Installation

To install GroupDocs.Conversion Cloud SDK for Java, add the following Maven dependency:

<repository>
    <id>repository.groupdocs.cloud</id>
    <name>repository.groupdocs.cloud</name>
    <url>https://releases.groupdocs.cloud/java/repo/</url>
</repository>
<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-conversion-cloud</artifactId>
    <version>24.2.0</version>
</dependency>

Ensure you have valid API credentials (Client ID and Client Secret). Follow this tutorial to obtain them.

Convert PDF to HTML using Java

Follow these steps to automate PDF to HTML conversion in Java:

  1. Initialize Configuration with API credentials:
Configuration configuration = new Configuration(clientId, clientSecret);
  1. Create an instance of ConvertApi:
ConvertApi convertApi = new ConvertApi(configuration);
  1. Upload the input PDF file to cloud storage:
FileApi fileApi = new FileApi(configuration);
UploadFileRequest uploadRequest = new UploadFileRequest("marketing.pdf", new FileInputStream("marketing.pdf"), "internal");
fileApi.uploadFile(uploadRequest);
  1. Create an instance of ConvertSettings class where we define the input PDF name, output format as html and the name of the resultant file:
ConvertSettings settings = new ConvertSettings();
settings.setStorageName("internal");
settings.setFilePath("input.pdf");
settings.setFormat("html");
settings.setOutputPath("finalOutput.html");
  1. Perform PDF to PPT conversion using ConvertDocumentRequest class where we pass ConvertSettings object as an argument:
ConvertDocumentRequest request = new ConvertDocumentRequest(settings);
convertApi.convertDocument(request);
free pdf to html online

Image:- A preview of PDF to HTML conversion.

Download the sample PDF file used in the above example from input.pdf.

Convert PDF to Web Page using cURL Commands

For command-line users, GroupDocs.Conversion Cloud API allows PDF to HTML conversion via cURL commands, making automation seamless.

  • Generate JWT Access Token with your credentials.
  • Run the following cURL command:
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"default\",  \"FilePath\": \"{sourcePDF}\",  \"Format\": \"html\",  \"OutputPath\": \"{finalOutput}\"}"

Replace sourceFile, resultantFile, and accessToken with actual values.

  • If you have a requirement to save the resultant HTML file on local drive, then please execute the following cURL command:
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"default\",  \"FilePath\": \"{sourceFile}\",  \"Format\": \"html\"}" \
-o "myFinaloutput.html"

Try Our Free PDF to HTML Converter

Use our PDF to HTML Converter for a quick and efficient online conversion experience.

Free PDF to PPT converter online

Conclusion

Whether using GroupDocs.Conversion Cloud SDK for Java or cURL commands, both approaches provide a fast, accurate, and flexible way to convert PDF to HTML. With cloud-based processing, high customization, and developer-friendly API, GroupDocs.Conversion Cloud simplifies document conversion. Try our Java SDK today for seamless PDF-to-HTML automation!

We highly recommend exploring the following articles: