10. Downloads
These functions trigger a file download in the user's browser. They live on context.document. The old context.downloadPDF names do not exist.
Templates are stored in the _Template entity. Record data is inserted with placeholders such as {{Record.InvoiceNumber}} or {{Record.IssuerCompany.Name}} for lookups.
context.document.pdf(entitySlug, recordId, templateId, fileName?, footerTemplate?, headerTemplate?)
async· returnsvoid
Generates and downloads a PDF from an HTML template merged with a record.
Prop
Type
context.component.updateByName("btnDownloadInvoice", "loading", true);
try {
const result = await context.sdk.entities.getById({
params: { entitySlug: "invoices", recordId: context.router.id }
});
const invoice = result?.data ?? result;
const issuerID = invoice.IssuerCompany?.ID;
const templateId = issuerID === 2 ? 26 : 25;
await context.document.pdf(
"invoices",
context.router.id,
templateId,
"invoice_" + invoice.InvoiceNumber + ".pdf"
);
} catch (error) {
context.toast.error("PDF download failed");
console.error(error);
} finally {
context.component.updateByName("btnDownloadInvoice", "loading", false);
}context.document.pdfWithBarCode(entitySlug, recordId, templateId, barCode, fileName?, footerTemplate?, headerTemplate?, templateValues?)
async· returnsvoid
Same as pdf, with a payment-barcode argument for invoices and slips.
Prop
Type
const invoice = (await context.sdk.entities.getById({
params: { entitySlug: "invoices", recordId: context.router.id }
}))?.data;
await context.document.pdfWithBarCode(
"invoices",
context.router.id,
25,
{
totalAmount: invoice.TotalAmount,
customerCompany: {
name: invoice.Company.Name,
adress: invoice.Company.Address,
cityWithPostalCode: invoice.Company.City
},
issuerCompany: {
name: invoice.IssuerCompany.Name,
adress: invoice.IssuerCompany.Address,
cityWithPostalCode: invoice.IssuerCompany.City,
IBAN: invoice.IssuerCompany.IBAN
},
referenceNumber: invoice.InvoiceNumber,
paymentDescription: "Invoice payment"
},
"invoice_" + invoice.InvoiceNumber + ".pdf"
);context.document.word(entitySlug, recordId, templateId, fileName?)
async· returnsvoid
await context.document.word("contracts", context.router.id, 14, "contract.docx");context.document.excel(payload, templateId, fileName)
async· returnsvoid
Fills a stored Excel template with the given payload.
await context.document.excel(
{ Month: "March 2026", TotalRevenue: 85000 },
18,
"monthly_report_march_2026.xlsx"
);context.document.file(url, payload, fileName)
async· returnsvoid
POSTs payload to url (absolute, or relative to the API) and downloads the response.
await context.document.file(
"/api/export/report",
{ from: "2026-01-01", to: "2026-03-31" },
"q1_report.pdf"
);