html to pdf online

Perform HTML to PDF conversion using Node.js SDK.

Converting HTML files or webpages to PDF is essential for generating printable documents, preserving layouts, and archiving content in a portable format. Using GroupDocs.Conversion Cloud SDK for Node.js, you can automate this process via REST API without needing any third-party tools or browser dependencies.

In this article, you’ll learn how to:

🌐 HTML to PDF Conversion API for Node.js

The GroupDocs.Conversion Cloud SDK for Node.js enables high-quality, scalable conversion from HTML to PDF format while maintaining design, layout, and embedded media.

📦 Install the SDK

Install using npm:

npm install groupdocs-conversion-cloud --save

Ensure that you have your personalized Client ID and Client Secret from the GroupDocs Cloud Dashboard. For further details, you may consider visiting this tutorial.

🚀 Convert HTML to PDF using 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 input HTML file to the Cloud storage:

const fs = require("fs");
const uploadRequest = new UploadFileRequest("input.html", fs.createReadStream("input.html"));
await fileApi.uploadFile(uploadRequest);

📌 Step 3: Set HTML to PDF conversion options:

const settings = new ConvertSettings();
settings.filePath = "input.html";
settings.format = "pdf";
settings.outputPath = "converted/output.pdf";

const request = new ConvertDocumentRequest(settings);
await convertApi.convertDocument(request);
console.log("✅ The HTML successfully converted to PDF.");
free html to pdf converter

Image:- A preview of HTML to PDF conversion.

Download the sample PDF file generated in the above example from resultant.pdf.

💻 Convert HTML to PDF with cURL

Do you prefer CLI? You can also convert HTML to PDF using cURL with GroupDocs.Conversion Cloud API endpoint.

  • ✅ This method is ideal for automation pipelines and script-based conversions.

Step 1: Get JWT Access Token

curl -v "https://api.groupdocs.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded"

Step 2: Convert HTML to PDF

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.

  • Now in order to save the PDF on local drive, you may consider using 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 HTML to PDF Converter Online

Want a fast no-code solution? Use the HTML to PDF Converter to transform web content instantly.

Free PDF to PPT converter online

✅ Conclusion

With GroupDocs.Conversion Cloud SDK for Node.js, you can quickly and reliably convert HTML to PDF—ideal for developers building document automation features or exporting styled HTML content as PDF.

Whether you’re embedding this in a Node.js backend or using it via cURL, this API offers flexibility and control.

🔗 Useful Resources

We recommend exploring the following articles: