@funbrew/pdf
v1.1.0
Published
FUNBREW PDF API client for Node.js
Readme
@funbrew/pdf
Official Node.js client library for the FUNBREW PDF API. Includes TypeScript type definitions.
Installation
npm install @funbrew/pdfQuick Start
const { FunbrewPdf } = require('@funbrew/pdf');
const pdf = new FunbrewPdf('sk-your-api-key');
// HTML to PDF
const result = await pdf.fromHtml('<h1>Hello World</h1>');
console.log(result.data.download_url);
// URL to PDF
const result = await pdf.fromUrl('https://example.com');
// Markdown to PDF
const result = await pdf.fromMarkdown('# Hello World', 'modern');
// List available Markdown themes
const themes = await pdf.markdownThemes();
// Template to PDF
const result = await pdf.fromTemplate('invoice', {
company_name: 'Acme Inc.',
amount: '1,000',
});Features
// Generate PDF and send via email
const result = await pdf.fromHtmlWithEmail(
'<h1>Invoice</h1>',
'[email protected]',
'Your invoice is ready',
);
// Test mode (no count, TEST watermark)
const result = await pdf.test('<h1>Test</h1>');
// File operations
const info = await pdf.info('uuid.pdf');
const buffer = await pdf.download('uuid.pdf');
require('fs').writeFileSync('output.pdf', buffer);
await pdf.delete('uuid.pdf');
// Batch generate
const batch = await pdf.batch([
{ type: 'html', html: '<h1>Doc 1</h1>' },
{ type: 'html', html: '<h1>Doc 2</h1>' },
]);
// Merge PDFs
const merged = await pdf.merge(['file1.pdf', 'file2.pdf']);
// Usage stats
const usage = await pdf.usage();Options
const result = await pdf.fromHtml('<h1>Hello</h1>', {
options: { 'page-size': 'A3', engine: 'quality' },
expiration_hours: 168,
max_downloads: 5,
password: 'secret',
watermark: 'CONFIDENTIAL',
});TypeScript
Full type definitions are included. No need for @types packages.
import { FunbrewPdf, PdfResult } from '@funbrew/pdf';
const pdf = new FunbrewPdf('sk-your-api-key');
const result: PdfResult = await pdf.fromHtml('<h1>Hello</h1>');Error Handling
const { FunbrewPdf, FunbrewError } = require('@funbrew/pdf');
try {
const result = await pdf.fromHtml('<h1>Hello</h1>');
} catch (e) {
if (e instanceof FunbrewError) {
console.error(e.message); // Error message
console.error(e.statusCode); // HTTP status code
}
}License
MIT
