pdf_generate()

Render HTML to a PDF and append it to a record's file-type field. Use it to produce invoices, receipts, or documents from record data.

Syntax

pdf_generate(table, id, fieldId, content, options?)

Parameters

Name Type Required Description
table string yes Table name or database table id.
id int yes The record's primary key.
fieldId string yes A file-type field id on that table — where the PDF is saved.
content string yes The HTML to render.
options array no See below.

options keys: orientation (portrait | landscape, default portrait), page_size (A4 / Letter / Legal), filename (saved file name; .pdf added if missing), header? / footer? (HTML), silent? (true suppresses follower notifications for the record update).

Returns

true on success. Throws if fieldId is not a file field or the record is missing.

Example

$html = "<h1>Invoice " . $record["number"] . "</h1>"
      . "<p>Total: $" . $record["total"] . "</p>";

pdf_generate("invoices", $record["_meta"]["id"], "documents", $html, [
    "filename"    => "invoice-" . $record["number"] . ".pdf",
    "orientation" => "portrait",
    "page_size"   => "A4"
]);

Example output

true

Notes

  • The PDF is appended to the field's existing files (nothing is overwritten).
  • Saving the file is a record update — followers are notified unless you pass ["silent" => true].
  • The HTML supports curated self-hosted fonts via font-family (including the Alex Brush signature script).
  • Generate then email a document by following this with record_email_send().

See also: record_email_send()