a9script

Docs / Language & functions

a9script authoring pack — documents functions

The documents functions, with their arguments and a line of real script each. Called by bare name; nothing is imported. A call marked pauses does real work outside the script: the run is saved, and continues on the next line with the result.

createPdf(document) — pauses

Draws a PDF and answers it as text you can file or send. You say what the document HOLDS — a list of blocks: headings, paragraphs, lists, tables, rules, gaps and page breaks — and how it is laid out is decided for you: text wraps, pages break where they must, and a table repeats its column names at the top of every page it runs onto. A document is set in the standard PDF fonts, which draw the Western alphabet; a character outside it — Greek, Cyrillic, Chinese, an emoji — is refused by name rather than drawn as something else.

  • document (object) — { title, blocks }. blocks is the list, drawn in the order you write it, and every block names its kind: heading (with level 1, 2 or 3, and text), text (with text), list (with items, and ordered to number them), table (with headers and rows), divider, spacer (with height in points) and pageBreak. Wherever text is expected you may also pass a number or true/false, and nothing at all writes an empty line — but a shape is refused, because there is no reading of it a person would want. title is the name the document carries: a reader meets it in their PDF viewer’s title bar, never on the page, so a title to be SEEN is a heading block. Any other key, any unknown kind, and any row that does not fit its headers, is refused naming the block it is in.

Answers: The document as base64 text — the same shape writeBlob takes, so a report can be built and filed in two lines. Building the same document twice answers exactly the same text: nothing about the moment it was built goes into it, which is also why a date a reader needs belongs in a block they can see.

const invoice = createPdf({
  title: "Invoice 4711",
  blocks: [
    { kind: "heading", level: 1, text: "Invoice 4711" },
    { kind: "text", text: "Thank you for your order." },
    { kind: "table", headers: ["item", "amount"], rows: [["Widget", 12.5], ["Delivery", 4]] },
    { kind: "divider" },
    { kind: "text", text: "Total: 16.50" }
  ]
});
log("the invoice is " + invoice.length + " characters of base64");
Rendered from docs/guide/authoring-pack-functions-document.md in the product's own repository, at build time. Found a problem on this page? Write to the address in the footer.