Back to Dashboard

PDF Email Attachment Workaround

A proven technique for reliable email delivery of PDF agreements

The Problem

When trying to generate PDFs dynamically within the approval/notification function and attach them to emails, you may encounter:

  • Complex jsPDF rendering logic scattered across multiple functions
  • Layout inconsistencies between portal downloads and email attachments
  • Timeouts due to intensive PDF generation in email handlers
  • Difficult-to-debug rendering differences

The Solution

Instead of reimplementing PDF generation, invoke your existing proven PDF function.

Call the generateClientPdf function (or your equivalent working PDF generator) from within your email handler. This ensures:

  • Perfect consistency between portal and email versions
  • Reuse of code that's already been tested and proven to work
  • Reduced complexity and maintenance burden
  • Single source of truth for PDF rendering logic

How to Implement

Step 1: Identify Your Working PDF Function

Find the backend function that successfully generates the PDF (e.g., generateClientPdf).

Step 2: Call It from Your Email Handler

// In your email/approval function
const pdfResponse = await base44.functions.invoke('generateClientPdf', {
  agreementId: agreement.id
});

const base64Pdf = pdfResponse.data.pdf;
const pdfBuffer = Buffer.from(base64Pdf, 'base64');

// Attach to email
await resendClient.emails.send({
  from: 'sender@example.com',
  to: guest.email,
  subject: 'Your Travel Agreement',
  html: htmlContent,
  attachments: [{
    filename: 'agreement.pdf',
    content: pdfBuffer
  }]
});

Step 3: Add Authorization Lock (Optional but Recommended)

Protect critical functions with an authorization code stored in AppSettings. Check the code before proceeding with expensive operations.

Key Benefits

Consistency

Same PDF in email as on portal

Reliability

Uses proven, tested code

Simplicity

No complex jsPDF logic in email handler

Maintainability

Single source of truth for PDF rendering

Performance

Avoids timeout issues with async invocation

DRY Principle

Don't Repeat Yourself—reuse existing code

When to Use This Pattern

  • ✓ You already have a working PDF generation function
  • ✓ You need to attach PDFs to emails
  • ✓ Consistency between portal and email versions is important
  • ✓ You want to reduce code complexity
  • ✓ You're experiencing timeout or rendering issues

Last Updated: March 13, 2026 | Technique: Function Composition Pattern