JSPM

siteforge-pdf

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q22597F
  • License MIT

Official Node.js SDK for SiteForge PDF - HTML to PDF conversion API

Package Exports

  • siteforge-pdf
  • siteforge-pdf/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (siteforge-pdf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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-pdf

Quick 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

  1. Sign up at pdf.siteforge.build
  2. Get your API key from the dashboard
  3. 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 --usage

TypeScript

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.

License

MIT © SiteForge