Real-time HTML to PDF/Image conversion client for Web2Docx API
npm install @web2docx/web2docx-sdkConvert HTML to PDF and Images using WebSocket-powered real-time API.
---
- Convert HTML to PDF (single)
- Convert multiple HTMLs to PDFs (batch, returns ZIP)
- Convert HTML to Image
- Real-time WebSocket updates for job completion
- Priority queueing (Free / Pro / Pro Max)
---
``bash`
npm i @web2docx/web2docx-sdk
or
`bash`
yarn add @web2docx/web2docx-sdk
---
To use this SDK, you need an API key.
๐ Sign up at web2docx.com and generate your key from the dashboard.
Free and paid plans are available based on usage.
---
`javascript
const { Web2DocxClient } = require("@web2docx/web2docx-sdk");
const client = new Web2DocxClient("YOUR_API_KEY");
`
---
`javascript
const fs = require("fs");
async function htmlToPdfExample() {
const html = "
fs.writeFileSync("output.pdf", pdfBuffer);
}
htmlToPdfExample();
`
---
`javascript
async function htmlBatchToPdfExample() {
const htmlList = ["First Document
", "Second Document
"];
const zipBuffer = await client.htmlBatchToPdf(htmlList);
fs.writeFileSync("batch-output.zip", zipBuffer);
}
htmlBatchToPdfExample();
`
> Note: Maximum 10 HTML documents per batch.
---
`javascript
async function htmlToImageExample() {
const html = "Hello Image
";
const imageBuffer = await client.htmlToImage(html);
fs.writeFileSync("output.png", imageBuffer);
}
htmlToImageExample();
`
---
`javascript
async function htmlBatchToImageExample() {
const htmlList = ["First Document
", "Second Document
"];
const zipBuffer = await client.htmlBatchToImage(htmlList);
fs.writeFileSync("batch-output.zip", zipBuffer);
}
htmlBatchToImageExample();
`
> Note: Maximum 10 HTML documents per batch.
---
`javascript
async function htmlToDocxExample() {
const html = "Hello Docx
";
const docxBuffer = await client.htmlToDocx(html);
fs.writeFileSync("output.docx", docxBuffer);
}
htmlToDocxExample();
`
---
`javascript
async function htmlBatchToDocxExample() {
const htmlList = ["First Document
", "Second Document
"];
const zipBuffer = await client.htmlBatchToDocx(htmlList);
fs.writeFileSync("batch-output.zip", zipBuffer);
}
htmlBatchToDocxExample();
`
> Note: Maximum 10 HTML documents per batch.
---
| Method | Description |
| :------------------------------------- | :--------------------------------------------------------------- |
| htmlToPdf(html: string) | Convert single HTML to PDF (returns Buffer) |htmlBatchToPdf(htmlList: string[])
| | Convert multiple HTMLs into a ZIP of PDFs (returns Buffer) |htmlToImage(html: string)
| | Convert single HTML to Image (returns Buffer) |htmlBatchToImage(htmlList: string[])
| | Convert multiple HTMLs into a ZIP of Images (returns Buffer) |htmlToDocx(html: string)
| | Convert single HTML to DOCX (returns Buffer) |htmlBatchToDocx(htmlList: string[])` | Convert multiple HTMLs into a ZIP of DOCX files (returns Buffer) |
|
---
- The SDK sends your request to the Web2Docx server.
- WebSocket connection is used to listen for job completion events.
- Once the server finishes conversion, your promise resolves automatically.
- Queues: Free users are slower; Pro and Pro Max users get faster processing.
---
- If a job takes more than 60 seconds, it times out and throws an error.
- Make sure your API Key is correct and active.
- Currently supports HTML input only (URL input coming soon).
---
MIT License
---
If you find Web2Docx useful, please consider giving us a star on GitHub โ it helps us reach more developers and motivates us to keep improving. Thank you! ๐
---
> Made with โค๏ธ by the Web2Docx team