puppeteer-html-image
A Node.js package to convert HTML to image and URL to screenshot using Puppeteer and Puppeteer Cluster.
Installation
Install the package via npm:
npm install puppeteer-html-image
Convert HTML to Image and URL To Image
import { htmlToImage, urlToImage } from "puppeteer-html-image";
// Convert HTML to Image
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
<title>Example HTML</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 0; }
.container { padding: 20px; }
h1 { color: #333; }
</style>
</head>
<body>
<div class="container">
<h1>Hello, World!</h1>
<p>This is an example HTML content rendered by Puppeteer.</p>
</div>
</body>
</html>
`;
htmlToImage(htmlContent, "html-screenshot.png");
// Convert URL to Image
urlToImage("https://example.com", "url-screenshot.png");
API
htmlToImage(htmlContent
: string, outputPath: string): Promise`
Converts the provided HTML content to an image and saves it to the specified output path.
htmlContent
: The HTML content to be rendered.
outputPath
: The path where the screenshot will be saved.
urlToImage(url: string, outputPath: string): Promise<void>
Takes a screenshot of the specified URL and saves it to the specified output path.
url
: The URL to be rendered.
outputPath
: The path where the screenshot will be saved.
Author
website: [https://subodha-protofolio-personal.netlify.app/]
Github: SubodhaSahu