UNPKG

safeer-pdf-generator

Version:

Framework-agnostic PDF generation library with chunking, merging, S3 upload, and email delivery

51 lines (43 loc) 1.5 kB
// Quick Reference: @safeersoft/@safeersoft/pdf-reporter Best Practices // ❌ DON'T: Over-configure with defaults const result = await generatePdf({ title: 'Report', data: myData, columns: myColumns, chunking: { chunkSize: 100, maxConcurrency: 2 }, // These are defaults! pdf: { format: 'A4', landscape: true }, // These are defaults! puppeteer: { args: ['--no-sandbox'] }, // These are defaults! }); // ✅ DO: Keep it simple const result = await generatePdf({ title: 'Report', data: myData, columns: myColumns, s3: { bucket: 'my-bucket', region: 'us-east-1' }, email: { to: 'user@example.com' }, // Gmail auto-configured! }); // ❌ DON'T: Manual error handling for email try { // complex email config with manual error checking } catch (error) { if (error.message.includes('socket close')) { // manual troubleshooting logic } } // ✅ DO: Let the library handle it const result = await generatePdf({ email: { to: 'user@example.com' } // Library provides detailed error messages automatically }); // ❌ DON'T: Check for defaults manually if (chunkSize !== 100) config.chunkSize = chunkSize; if (port !== 587) config.port = port; // ✅ DO: Only set what you need to change const result = await generatePdf({ chunking: { chunkSize: 50 }, // Only if different from default email: { to: 'user@example.com', smtp: { host: 'custom-smtp.com' } // Only if not Gmail } }); // 🎯 RESULT: 90% less code, better error handling, easier maintenance