Autorun AI Docs
Process DesignerBusiness FunctionBusiness Functions Reference

8. Document Generation


generatePDF(generatePdfRequest)

async · returns byte[]

Generates a PDF document and returns the raw bytes. Use this when you need binary content directly — for embedding, storing, or attaching to an email.

Prop

Type

const pdfBytes = await context.functions.generatePDF({
  templateId: "invoice-template",
  recordId: context.record.ID,
  width: 210,
  height: 297
});

// Encode as Base64 for storage or transmission
const base64 = btoa(String.fromCharCode(...new Uint8Array(pdfBytes)));

Returned value — a raw byte array representing the PDF binary:

// → JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFI...

generatePdfString(generatePdfRequestObject)

async · returns string (Base64)

A convenience variant of generatePDF that returns the PDF encoded as a Base64 string. Ideal for storing in a text field or passing to an API that expects Base64.

Prop

Type

const base64Pdf = await context.functions.generatePdfString({
  templateId: "invoice-template",
  recordId: context.record.ID,
  width: 210,
  height: 297
});

await context.functions.update("documents", context.record.ID, { PdfData: base64Pdf });

Returned value — a Base64-encoded string of the full PDF content:

"JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFI..."

GenerateWordFileAsync(slug, id, userId, templateID)

async · returns string

Generates a Word (.docx) document by merging a specific record's data into a Word template. Returns the file identifier of the generated document.

Prop

Type

const filePath = await context.functions.GenerateWordFileAsync(
  "contracts",
  context.record.ID,
  context.user.id,
  42
);

log("Generated Word file at: " + filePath);
// → "generated/contracts_record_55_template_42.docx"

Returned value — a string containing the file path or media library identifier of the generated document:

"generated/contracts_record_55_template_42.docx"