Transforming Word documents into clean HTML is a frequent requirement in today's web applications, whether you're developing content management systems, email editors, or document preview tools. Utilizing the GroupDocs.Conversion Cloud Node.js SDK allows developers to achieve fast, reliable, and scalable conversion from Word to HTML with just a few lines of JavaScript. There’s no requirement to depend on bulky libraries or complicated DOM parsing.
The Node.js REST API manages the complex tasks by securely converting DOC or DOCX files in the cloud and providing well-structured HTML output. This ensures that layout integrity, styling, and even embedded images are preserved accurately. It is highly suitable for teams engaged in dynamic user interfaces, document-centric workflows, or automated content distribution systems.
Incorporating this Cloud SDK can ease development, lessen code complexity, and speed up delivery timelines. It is tailored for real-time document rendering within web applications, offers various export options, and operates smoothly across different settings. Experiment with the REST API and enhance document conversion in your JavaScript projects by consulting our comprehensive guide.
The code example provided below will assist you in integrating this capability into your Node.js applications:
// Step 1: Import the GroupDocs.Conversion.Cloud module
const conversion_cloud = require("groupdocs-conversion-cloud");
// Step 2: Define your API credentials
const MyAppKey = "your-app-key";
const MyAppSid = "your-app-sid";
// Step 3: Initialize the ConvertApi with API credentials
const convertApi = conversion_cloud.ConvertApi.fromKeys(MyAppKey, MyAppSid);
// Step 4: Convert Word to HTML
(async () => {
try {
// Instantiate the ConvertSettings class and set values
const settings = new conversion_cloud.ConvertSettings();
settings.filePath = "SampleFiles/source.docx"; // Input file in cloud storage
settings.format = "html"; // Output format
settings.outputPath = "converter/converted.html"; // Output file path
// Apply the Word DOCX load options
const loadOptions = new conversion_cloud.WordProcessingLoadOptions();
loadOptions.pageNumbering = true;
settings.loadOptions = loadOptions;
// Set HTML conversion options
const convertOptions = new conversion_cloud.WebConvertOptions();
convertOptions.fromPage = 1;
convertOptions.pagesCount = 2;
settings.convertOptions = convertOptions;
// Create and process Word to HTML conversion request
const request = new conversion_cloud.ConvertDocumentRequest(settings);
await convertApi.convertDocument(request);
} catch (error) {
console.error("Error during file conversion:", error.message);
}
})();
Top comments (0)