HTML to IMAGE

const { Web2DocxClient } = require("@web2docx/web2docx-sdk");

const client = new Web2DocxClient("YOUR_API_KEY");

async function htmlToImageExample() {
  const html = "<h1>Hello Image</h1>";
  const imageBuffer = await client.htmlToImage(html);
  require("fs").writeFileSync("output.png", imageBuffer);
}

htmlToImageExample();

HTML File to IMAGE

const { Web2DocxClient } = require("@web2docx/web2docx-sdk");
const fs = require("fs");
const path = require("path");

const client = new Web2DocxClient("YOUR_API_KEY");

const htmlFile = fs.readFileSync(path.join(__dirname, "sample.html"), "utf8"); 

async function htmlFileToPngExample() {
  const html = htmlFile;
  const pdfBuffer = await client.htmlToImage(html);

  fs.writeFileSync("output.pdf", pdfBuffer);
}

htmlFileToPngExample();
Updated on