screenshot-pdf-api
v1.1.0
Published
Official Node.js wrapper for the Screenshot & PDF API. Capture screenshots, generate PDFs, extract metadata, and render HTML to images.
Downloads
181
Maintainers
Readme
screenshot-pdf-api
Official Node.js wrapper for the Screenshot & PDF API. Capture screenshots, generate PDFs, extract metadata, and render HTML to images -- all from a simple API.
Zero dependencies -- uses native fetch (Node 18+).
Get Your API Key
Subscribe on RapidAPI to get your key. Three tiers available:
| Tier | Endpoints | Rate Limit | |------|-----------|------------| | Free | health, screenshot | 100 req/day | | Basic | + pdf, metadata | 1,000 req/day | | Pro | + htmlScreenshot (HTML/CSS render) | 10,000 req/day |
Install
npm install screenshot-pdf-apiQuick Start
import ScreenshotAPI from 'screenshot-pdf-api';
import { writeFileSync } from 'fs';
const api = new ScreenshotAPI('your-rapidapi-key');
// Take a screenshot
const png = await api.screenshot({ url: 'https://example.com' });
writeFileSync('example.png', png);
// Generate a PDF
const pdf = await api.pdf({ url: 'https://example.com' });
writeFileSync('example.pdf', pdf);CommonJS
const ScreenshotAPI = require('screenshot-pdf-api');
const api = new ScreenshotAPI('your-rapidapi-key');
const png = await api.screenshot({ url: 'https://example.com' });API Reference
Constructor
// Simple -- just pass your key
const api = new ScreenshotAPI('your-rapidapi-key');
// Advanced options
const api = new ScreenshotAPI({
apiKey: 'your-rapidapi-key',
timeout: 60000, // 60s timeout (default: 30s)
});Methods
All methods return a Promise and throw ScreenshotAPIError on failure.
api.health()
Check API status and queue depth. No authentication required.
const status = await api.health();
// { status: 'healthy', browser: 'connected', queue: 0, max_concurrent: 3, version: '1.0' }api.screenshot(params) -- Free tier
Capture a screenshot of any URL. Returns a Buffer containing the image data.
| Param | Type | Default | Description |
|-------|------|---------|-------------|
| url | string | required | URL to capture |
| width | number | 1280 | Viewport width in px |
| height | number | 800 | Viewport height in px |
| format | string | "png" | png, jpeg, or webp |
| quality | number | 85 | Quality 1-100 (jpeg/webp only) |
| full_page | boolean | false | Capture full scrollable page |
| delay | number | 0 | Wait delay in seconds before capture |
| selector | string | null | CSS selector to capture a specific element |
// Basic screenshot
const png = await api.screenshot({ url: 'https://github.com' });
writeFileSync('github.png', png);
// Full-page screenshot as WebP
const webp = await api.screenshot({
url: 'https://github.com',
format: 'webp',
full_page: true,
quality: 90,
});
// Capture a specific element
const logo = await api.screenshot({
url: 'https://github.com',
selector: '.header-logo',
});api.pdf(params) -- Basic tier
Generate a PDF from any URL. Returns a Buffer containing the PDF data.
| Param | Type | Default | Description |
|-------|------|---------|-------------|
| url | string | required | URL to convert |
| format | string | "A4" | A4, Letter, Legal, A3, A5, Tabloid |
| landscape | boolean | false | Landscape orientation |
| print_background | boolean | true | Include background graphics |
| margin | string | "normal" | normal, none, narrow, wide |
// Default A4 PDF
const pdf = await api.pdf({ url: 'https://example.com' });
writeFileSync('page.pdf', pdf);
// Landscape Letter with no margins
const report = await api.pdf({
url: 'https://example.com/report',
format: 'Letter',
landscape: true,
margin: 'none',
});api.metadata(url) -- Basic tier
Extract title, Open Graph tags, favicon, word count, and link counts from a URL.
const meta = await api.metadata('https://github.com');
console.log(meta.data.title); // "GitHub: Let's build from here"
console.log(meta.data.og_image); // "https://github.githubassets.com/..."
console.log(meta.data.word_count); // 1234api.htmlScreenshot(params) -- Pro tier
Render raw HTML/CSS to an image. Returns a Buffer.
| Param | Type | Default | Description |
|-------|------|---------|-------------|
| html | string | required | HTML content to render |
| width | number | 1280 | Viewport width in px |
| height | number | 800 | Viewport height in px |
| format | string | "png" | png, jpeg, or webp |
const img = await api.htmlScreenshot({
html: '<h1 style="color: red;">Hello World</h1>',
width: 800,
height: 600,
});
writeFileSync('rendered.png', img);Error Handling
import ScreenshotAPI, { ScreenshotAPIError } from 'screenshot-pdf-api';
const api = new ScreenshotAPI('your-key');
try {
const png = await api.screenshot({ url: 'https://example.com' });
} catch (err) {
if (err instanceof ScreenshotAPIError) {
console.error(`API Error ${err.status}: ${err.message}`);
console.error('Response body:', err.body);
}
}TypeScript
Full TypeScript support is included out of the box. All types are exported:
import ScreenshotAPI, {
ScreenshotParams,
PdfParams,
MetadataResponse,
HtmlScreenshotParams,
} from 'screenshot-pdf-api';
const api = new ScreenshotAPI('your-key');
const meta: MetadataResponse = await api.metadata('https://example.com');Requirements
- Node.js 18+ (uses native
fetch)
License
MIT
