safeer-pdf-generator
Version:
Framework-agnostic PDF generation library with chunking, merging, S3 upload, and email delivery
52 lines (46 loc) • 1.37 kB
JavaScript
// Simple standalone usage - just 15 lines!
import { generatePdf } from '@safeersoft/@safeersoft/pdf-reporter';
async function generateReport() {
const result = await generatePdf({
title: 'My Report',
data: [
{ name: 'John', age: 30, city: 'New York' },
{ name: 'Jane', age: 25, city: 'Los Angeles' }
],
columns: [
{ key: 'name', label: 'Name' },
{ key: 'age', label: 'Age' },
{ key: 'city', label: 'City' }
],
// Optional: Upload to S3
s3: {
bucket: 'my-bucket',
region: 'us-east-1',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
// Optional: Send via email
email: {
to: 'user@example.com',
smtp: {
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
},
},
});
console.log(`PDF generated: ${result.s3?.url}`);
console.log(`Processing time: ${result.durationMs}ms`);
}
// That's it! The library handles:
// ✅ Smart SMTP defaults (Gmail auto-configured)
// ✅ Error handling with helpful messages
// ✅ Auto-validation and correction
// ✅ Connection testing
// ✅ Chunking for large datasets
// ✅ PDF optimization
// ✅ Template generation