1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Report Functions
  8. /
  9. Page by Page Functions

Page by Page Functions

Page by Page email functions allow Articles reports to send individual pages of a report to different email recipients. This is useful for reports where each page belongs to a specific person or account โ€” such as statements, pay slips, or invoices โ€” and each recipient should only receive their own page.

The typical workflow is to call PagebyPageEmailAdd once for each page during the report’s OnAfterPrintPage event to build up the email list, then call PagebyPageEmailShow at the end of the report to send or review the emails.


PagebyPageEmailAdd

Adds an email entry for a specific report page. Call this once per page โ€” typically in the report’s OnAfterPrintPage event โ€” to associate a page number with a recipient’s email address, name, subject, and message body.

procedure PagebyPageEmailAdd(
  EmailAddress, EmailName, Subject, Body, AttachmentName: String;
  SSendEmail: Boolean;
  PageNumber: Integer
)
ParameterTypeDescription
EmailAddressStringThe recipient’s email address
EmailNameStringThe recipient’s display name
SubjectStringThe email subject line
BodyStringThe email message body
AttachmentNameStringThe filename to use for the attached PDF page
SSendEmailBooleanTrue to send automatically, False to queue for review
PageNumberIntegerThe report page number this email is for
// Typical use in an OnAfterPrintPage event handler
// Each customer statement page is emailed to the matching customer

procedure frxReport1AfterPrintPage(Sender: TObject);
begin
  PagebyPageEmailAdd(
    [Customer.Email],
    [Customer.CompanyName],
    'Your Statement for ' + FormatDateTime('mmmm yyyy', Date),
    'Please find your account statement attached.' + #13#10 +
    'Contact us if you have any questions.',
    'Statement_' + TrimSafe([Customer.AccountNo]) + '.pdf',
    True,
    Engine.CurPage
  );
end;
// Pay slip example โ€” each employee receives only their own page
PagebyPageEmailAdd(
  [Employee.Email],
  [Employee.FullName],
  'Your Pay Slip โ€” ' + FormatDateTime('mm/dd/yyyy', [Payroll.PeriodEnd]),
  'Your pay slip for the period ending ' +
  FormatDateTime('mm/dd/yyyy', [Payroll.PeriodEnd]) + ' is attached.',
  'PaySlip_' + TrimSafe([Employee.EmployeeNo]) + '.pdf',
  True,
  Engine.CurPage
);

PagebyPageEmailClear

Clears all emails that have been queued by PagebyPageEmailAdd. Call this at the start of a report run to ensure no leftover emails from a previous run are included.

procedure PagebyPageEmailClear()
// Clear at the start of a report to reset the email queue
// Typically called in the report's OnStartReport event

procedure frxReport1StartReport(Sender: TObject);
begin
  PagebyPageEmailClear();
end;
// Also useful if you need to restart the email queue mid-report
// due to an error or condition change
PagebyPageEmailClear();

PagebyPageEmailShow

Displays the Page by Page email send dialog, allowing the user to review and send all emails that have been queued during the report run. Call this after the report has finished printing, typically in the report’s OnStopReport event.

procedure PagebyPageEmailShow()
// Show the send dialog when the report finishes
// Typically called in the report's OnStopReport event

procedure frxReport1StopReport(Sender: TObject);
begin
  PagebyPageEmailShow();
end;
// You can conditionally show it only when emails were added
// For example, only show if the user chose to email statements
if [Param.SendByEmail] then
  PagebyPageEmailShow();

Complete Page by Page Workflow Example

The following shows the full three-step pattern used in a customer statement report where each page is emailed to a different customer.

// Step 1 โ€” OnStartReport: clear the queue
procedure frxReport1StartReport(Sender: TObject);
begin
  PagebyPageEmailClear();
end;

// Step 2 โ€” OnAfterPrintPage: add an email for each page
procedure frxReport1AfterPrintPage(Sender: TObject);
begin
  if TrimSafe([Customer.Email]) <> '' then
    PagebyPageEmailAdd(
      [Customer.Email],
      [Customer.CompanyName],
      'Account Statement โ€” ' + FormatDateTime('mmmm yyyy', Date),
      'Dear ' + TrimSafe([Customer.ContactName]) + ',' + #13#10 + #13#10 +
      'Please find your account statement for ' +
      FormatDateTime('mmmm yyyy', Date) + ' attached.' + #13#10 + #13#10 +
      'Thank you for your business.',
      'Statement_' + CleanNumber([Customer.AccountNo]) + '.pdf',
      True,
      Engine.CurPage
    );
end;

// Step 3 โ€” OnStopReport: show the send dialog
procedure frxReport1StopReport(Sender: TObject);
begin
  PagebyPageEmailShow();
end;