
How to convert PDF to HTML with Node.js API.
Converting documents to is essential for displaying files on the web, improving accessibility, and integrating documents into digital workflows. In this article, you’ll learn how to convert PDF to HTML in Node.js using the GroupDocs.Conversion Cloud SDK, a powerful REST API that simplifies document transformation.
We are going to cover following topics in this article:
- 🌐 PDF to HTML Conversion API for Node.js
- 🚀 Convert PDF to HTML in Node.js
- 💻 Convert PDF to HTML Online via cURL
🌐 PDF to HTML Conversion API for Node.js
GroupDocs.Conversion Cloud SDK for Node.js provides a reliable and accurate way to convert PDF files into HTML format while retaining layout, fonts, images, and structure. You can also customize output settings such as image quality and page ranges.
📦 Installation
Use npm to install the SDK::
npm install groupdocs-conversion-cloud --save
Ensure that you have your Client ID and Client Secret from the GroupDocs Cloud Dashboard. For further details, you may consider visiting this tutorial.
🚀 Convert PDF to HTML in Node.js
Here’s a step-by-step guide for converting a PDF document to HTML using Node.js:
📌 Step 1: Import SDK and configure API:
const { Configuration, ConvertApi, FileApi, UploadFileRequest, ConvertSettings, ConvertDocumentRequest } = require("groupdocs-conversion-cloud");
const config = new Configuration("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
const convertApi = new ConvertApi(config);
const fileApi = new FileApi(config);
📌 Step 2: Upload the PDF file to the Cloud storage:
const fs = require("fs");
const uploadRequest = new UploadFileRequest("input.json", fs.createReadStream("input.pdf"));
await fileApi.uploadFile(uploadRequest);
📌 Step 3: Set conversion options for PDF to HTML:
const settings = new ConvertSettings();
settings.filePath = "input.pdf";
settings.format = "html";
settings.outputPath = "converted/output.html";
const request = new ConvertDocumentRequest(settings);
await convertApi.convertDocument(request);
console.log("✅ JSON converted to HTML successfully.");
// More examples over https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet | |
// Obtain your API credentials | |
string clientId = "XXXXXX-XXXXXXXXX-4088-9ca0-55c38f4b7f22"; | |
string clientSecret1 = "XXXXXXXXXXXXXXXXXXXX"; | |
// Create an instance of the Configuration class and initialize it with the Client ID & Client Secret | |
Configuration configuration = new Configuration(clientId, clientSecret); | |
// Define the API base URL to perform PDF to HTML conversion online | |
configuration.setApiBaseUrl("https://api.groupdocs.cloud"); | |
// Initialize an instance of ConvertApi with the Configuration object | |
ConvertApi convertApi = new ConvertApi(configuration); | |
ConvertSettings settings = new ConvertSettings(); | |
settings.setStorageName("internal"); | |
settings.setFilePath("input.pdf"); | |
settings.setFormat("HTML"); | |
settings.setOutputPath("myResultant.html"); | |
// Use ConvertDocument method to convert PDF file to HTML web page | |
ConvertDocumentRequest request = new ConvertDocumentRequest(settings); | |
List<StoredConvertedResult> response = convertApi.convertDocument(request); | |
// Check the response and print success message | |
if (response != null && response.equals("OK")) { | |
System.out.println("The PDF to HTML conversion completed successfuly! Resultant HTML file is saved at: " + response.getFilePath()); | |
} |
Image:- A preview of PDF to HTML conversion.
Download the sample PDF file used in the above example from input.pdf.
💻 Convert PDF to HTML Online via cURL
You can also convert PDF to HTML online using cURL and GroupDocs.Conversion Cloud API endpoint:
- Generate your JWT access token.
- Use 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.
- To save the HTML on local drive, 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 "myOutput.html"
🧪 Try Free PDF to HTML Converter Online
Use our PDF to HTML Converter for a quick and efficient online conversion experience.
✅ Conclusion
By using GroupDocs.Conversion Cloud SDK for Node.js or its REST API endpoints, the conversion of PDF to HTML becomes easy, accurate, and scalable. The API preserves structure and supports various output options, making it ideal for developers building web-based document viewers or editors.
🔗 Useful Links
📚 Related Articles
We highly recommend exploring the following articles: