siteforge-pdf
v1.0.0
Published
Official Node.js SDK for SiteForge PDF - HTML to PDF conversion API
Maintainers
Readme
SiteForge PDF
Official Node.js SDK for SiteForge PDF — simple HTML to PDF conversion API.
- ⚡ 100 free conversions/month
- 💳 Pay-as-you-go: $0.02 per conversion after free tier
- 🚀 Fast: Sub-second conversion times
- 📄 Simple: Just send HTML, get PDF
Installation
npm install siteforge-pdfQuick Start
const pdf = require('siteforge-pdf');
const fs = require('fs');
// Initialize with your API key
const client = pdf('sf_pdf_your_api_key');
// Convert HTML to PDF
const buffer = await client.convert('<h1>Hello World</h1>');
fs.writeFileSync('hello.pdf', buffer);Get Your API Key
- Sign up at pdf.siteforge.build
- Get your API key from the dashboard
- Start converting!
Usage
Convert HTML
const pdf = require('siteforge-pdf');
const client = pdf('sf_pdf_your_key');
// Simple HTML
const buffer = await client.convert('<h1>Invoice #123</h1><p>Amount: $100</p>');
// With options
const buffer = await client.convert(html, {
format: 'Letter', // A4, Letter, Legal
landscape: true, // Landscape orientation
margin: 'small', // none, small, default, large
printBackground: true // Include background colors/images
});
fs.writeFileSync('invoice.pdf', buffer);Convert URL
// Convert any public URL to PDF
const buffer = await client.convertUrl('https://example.com');
// With options
const buffer = await client.convertUrl('https://example.com', {
format: 'A4',
waitMs: 1000 // Wait for JS to render
});
fs.writeFileSync('example.pdf', buffer);Check Usage
const usage = await client.usage();
console.log(usage);
// {
// plan: 'free',
// period: '2024-01',
// currentMonth: { conversions: 42, ... },
// limits: { monthly: 100, remaining: 58 }
// }CLI
The package includes a command-line tool:
# Set your API key
export SITEFORGE_PDF_KEY=sf_pdf_your_key
# Convert HTML
siteforge-pdf --html "<h1>Hello</h1>" -o hello.pdf
# Convert a file
siteforge-pdf --file invoice.html -o invoice.pdf
# Convert a URL
siteforge-pdf --url https://example.com -o example.pdf
# With options
siteforge-pdf --html "<h1>Report</h1>" -o report.pdf --landscape --format Letter
# Check usage
siteforge-pdf --usageTypeScript
Full TypeScript support included:
import pdf, { SiteForgePDF, ConvertOptions } from 'siteforge-pdf';
const client: SiteForgePDF = pdf('sf_pdf_your_key');
const options: ConvertOptions = {
format: 'A4',
landscape: false
};
const buffer: Buffer = await client.convert('<h1>Hello</h1>', options);Options
Client Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| baseUrl | string | https://pdf.siteforge.build | API base URL |
| timeout | number | 60000 | Request timeout in ms |
Convert Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| format | string | 'A4' | Page format: A4, Letter, Legal |
| landscape | boolean | false | Landscape orientation |
| margin | string | 'default' | Margin: none, small, default, large |
| printBackground | boolean | true | Include background graphics |
| waitMs | number | 0 | Wait before capture (for JS rendering) |
Error Handling
const pdf = require('siteforge-pdf');
const client = pdf('sf_pdf_your_key');
try {
const buffer = await client.convert('<h1>Hello</h1>');
fs.writeFileSync('output.pdf', buffer);
} catch (err) {
if (err.statusCode === 401) {
console.error('Invalid API key');
} else if (err.statusCode === 429) {
console.error('Rate limit exceeded');
} else {
console.error('Conversion failed:', err.message);
}
}Pricing
| Plan | Monthly Conversions | Price | |------|---------------------|-------| | Free | 100 | $0 | | Pay-as-you-go | Unlimited | $0.02 each |
Free tier includes a small watermark. Upgrade to PAYG for watermark-free PDFs.
Links
License
MIT © SiteForge
