Documentation

Quick Start
Installation
CLI Reference
Scripting
Environment Functions
PDF Functions
Demo Script (AI-generated)
License Activation


Quick Start

Follow these steps to generate your first PDF report with AlfaReport.

Step 1: Download the executable

Choose the appropriate binary for your system architecture from the download page, then download AlfaReport:

wget -O alfareport https://alfareport.com/download/v1.0/x64/alfareport

Supported architectures: x64, x86, arm, riscv, mips, mipsel. Replace x64 with your architecture if needed.

Step 2: Set execute permission

chmod +x alfareport

Step 3: Add to PATH

To run alfareport from any location, add it to your PATH:

# For current session
export PATH="$PATH:$(pwd)"

# Make permanent
echo 'export PATH="$PATH:'$(pwd)'"' >> ~/.bashrc

Step 4: Create a "Hello World" script

Create a script named hello.js:

const pdf = new PDF();
pdf.text("Hello, World!");
pdf.save("hello.pdf");

Step 5: Run the script

alfareport hello.js

Or if you didn't add to PATH:

./alfareport hello.js

Result

You should see hello.pdf created in your current directory. Open it to view your first generated report!


Installation

Step 1: Download the executable

Choose the appropriate binary for your system architecture from the download page, then use wget to download AlfaReport to your current directory:

Supported architectures: x64, x86, arm, riscv, mips, mipsel.

wget -O alfareport https://alfareport.com/download/v1.0/x64/alfareport

If you encounter SSL certificate issues, use:

wget --no-check-certificate -O alfareport https://alfareport.com/download/v1.0/x64/alfareport

Alternatively, with curl:

curl -L -o alfareport https://alfareport.com/download/v1.0/x64/alfareport

Step 2: Set execute permission

Make the downloaded file executable:

chmod +x alfareport

Step 3: Add to PATH (optional but recommended)

To run alfareport from any location without specifying the full path, add the executable directory to your system PATH:

# Add to PATH for current session
export PATH="$PATH:/path/to/alfareport/directory"

# Make permanent (add to ~/.bashrc, ~/.zshrc, or ~/.profile)
echo 'export PATH="$PATH:/path/to/alfareport/directory"' >> ~/.bashrc

CLI Reference

Usage

alfareport js_script [options]

Arguments

Examples

alfareport script.js
alfareport script.js -s
alfareport script.js -p title="My Report" -p format=A4
alfareport mylib.js report.js -t 1000
alfareport script.js -l XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX
alfareport --version

Scripting

AlfaReport supports JavaScript syntax up to ES2020, including:

To generate a PDF document, you must create an instance of the built-in PDF class and use its methods. The available methods are described in the following sections.

Basic Example

const pdf = new PDF();
pdf.text("Hello, World!");
pdf.save("output.pdf");

Using async/await

AlfaReport does not support await at the top-level of a script (top-level await). If you use await—for example, when calling fetch—all code containing it must be inside an async function. The simplest way is to wrap the entire script body in the main function and call it.

async function main() {
    const res = await fetch("https://api.example.com/data");
    const data = await res.json();

    const pdf = new PDF();
    pdf.text(data.title);
    pdf.save("output.pdf");
}

main();

Environment Functions

readText(path)
readJSON(path)
fetch(url, options)


readText(path)

Reads a file and returns its contents as a string.

Parameters

Returns (string) — file contents, or null if the file does not exist. Throws an error if the file could not be read.

Example

const text = readText("template.txt");

readJSON(path)

Reads a file and parses its contents as JSON.

Parameters

Returns (object) — parsed JSON value, or undefined if the file does not exist. Throws an error if the file could not be read or contains invalid JSON.

Example

const data = readJSON("config.json");

fetch(url, options)

Performs an HTTP request. Returns a Promise, similar to the browser Fetch API.

Parameters

Returns (Promise) — resolves with the response object. Rejects on network error or timeout.

Example

const res = await fetch("https://api.example.com/data", {
    method: "POST",
    headers: { "Authorization": "Bearer TOKEN" },
    body: { key: "value" },
    timeout: 5000,
});

PDF Functions

new PDF(pageSize, pageDirection, defaultFont)
pdf.text(text, x, y, width, lineSpacing, align)
pdf.font(name, size)
pdf.fontSize(size)
pdf.textColor(color)
pdf.fillColor(color)
pdf.strokeColor(color)
pdf.strokeWidth(width)
pdf.pageColor(color)
pdf.line(x1, y1, x2, y2)
pdf.rect(x, y, width, height, border)
pdf.ellipse(x, y, width, height, border)
pdf.image(file, x, y, width, height)
pdf.link(url, x, y, width, height, k)
pdf.textBounds(text, width, lineSpacing)
pdf.getMetrics()
pdf.resetBounds()
pdf.padding(left, right, top, bottom)
pdf.newPage()
pdf.gotoPage(pageNumber)
pdf.getPageCount()
pdf.paginate(options)
pdf.table(table, cells)
pdf.sign(options, callback)
pdf.save(path)


new PDF(pageSize, pageDirection, defaultFont)

Creates a new PDF document with a single blank page.

Parameters

Example

const pdf = new PDF("A4", "portrait", "sans");

pdf.text(text, x, y, width, lineSpacing, align)

Renders text on the current page.

Parameters

Example

pdf.text("Hello, World!", 0, 100, 400, 1, "center");

pdf.font(name, size)

Sets the font for subsequent text rendering.

Parameters

Example

pdf.font("sans_bold", 12);

pdf.fontSize(size)

Sets the font size without changing the font family.

Parameters

Example

pdf.fontSize(14);

pdf.textColor(color)

Sets the text color.

Parameters

Example

pdf.textColor("#333333");

pdf.fillColor(color)

Sets the fill color for shapes.

Parameters

Example

pdf.fillColor("#f0f0f0");

pdf.strokeColor(color)

Sets the stroke color for shapes and lines.

Parameters

Example

pdf.strokeColor("#000000");

pdf.strokeWidth(width)

Sets the stroke width for shapes and lines.

Parameters

Example

pdf.strokeWidth(2);

pdf.pageColor(color)

Sets the background color for current page.

Parameters

Example

pdf.pageColor("#ffffcc");

pdf.line(x1, y1, x2, y2)

Draws a line between two points.

Parameters

Example

pdf.line(0, 200, 500, 200);

pdf.rect(x, y, width, height, border)

Draws a rectangle.

Parameters

Example

pdf.rect(0, 100, 400, 50);

pdf.ellipse(x, y, width, height, border)

Draws an ellipse.

Parameters

Example

pdf.ellipse(100, 200, 80, 80);

pdf.image(file, x, y, width, height)

Places an image on the current page.

Parameters

Example

pdf.image("logo.png", 0, 100, 200, 50);

pdf.link(url, x, y, width, height, k)

Places a clickable hyperlink area on the current page.

Parameters

Example

pdf.link("https://example.com", 0, 100, 200, 20);

pdf.textBounds(text, width, lineSpacing)

Calculates the bounding box of a text block without rendering it.

Parameters

Returns an object:

Example

const bounds = pdf.textBounds("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", 200);
console.log(bounds);

pdf.getMetrics()

Returns layout metrics for the current page.

Returns an object:

Example

const m = pdf.getMetrics();
console.log(m.innerWidth, m.innerHeight);

pdf.resetBounds()

Resets the affected bounds tracking (left, right, top, bottom) to zero.

Example

pdf.resetBounds();

pdf.padding(left, right, top, bottom)

Sets the page padding.

Parameters

Example

pdf.padding(20, 20, 40, 40);

pdf.newPage()

Adds a new page to the document.

Example

pdf.newPage();

pdf.gotoPage(pageNumber)

Switches the current drawing context to an existing page.

Parameters

Example

pdf.gotoPage(1);

pdf.getPageCount()

Returns the total number of pages in the document.

Returns (number)

Example

const count = pdf.getPageCount();

pdf.paginate(options)

Adds page numbers to all pages.

Parameters

Example

pdf.paginate({ format: "Page {PAGE}", halign: "right", valign: "bottom" });

pdf.table(table, cells)

Renders a table on the current page. Supports flexible configuration of structure, dimensions, padding, borders, and styles for both the whole table and individual cells.

Parameters

Notes

Example

pdf.table(
    { cols: 3, border: 0.5, headerBgColor: "#eeeeee" },
    [
        { text: "Name", halign: "center" },
        { text: "Age",  halign: "center" },
        { text: "City", halign: "center" },
        "Alice", "30", "New York",
        "Bob",   "25", "London",
    ]
);

pdf.sign(options, callback)

Signs the document with a digital certificate. The operation is asynchronous — result is delivered via callback.

Parameters

Example

pdf.sign(
    {
        certPath: "cert.pem",
        keyPath: "key.pem",
        chainPath: "chain.pem",
        tsaEnabled: true,
        tsaUrl: "http://timestamp.digicert.com",
        rectEnabled: true,
        rectX: 50, rectY: 700, rectWidth: 200, rectHeight: 50,
        rectText: "Signed by Alice",
        rectFillColor: "#f0f0f0",
    },
    (err) => {
        if (err) throw err;
        pdf.save("signed.pdf");
    }
);

pdf.save(path)

Saves the document to disk. If the document has not been signed, a watermark may be applied depending on the library configuration.

Parameters

Example

pdf.save("output.pdf");

Demo Script (AI-generated)

The demo.js file is a complete working example covering every available API function — environment utilities (readText, readJSON, fetch), all PDF drawing and layout methods, tables, pagination.

It was generated entirely by an AI assistant based solely on this documentation, without any manual coding. This demonstrates that AlfaReport's API is straightforward enough to be used by AI agents out of the box: you can describe the report you need in plain language and let an AI write the script for you.

You can download demo.js and execute it:

alfareport demo.js

See result in demo_output.pdf.

License Activation

AlfaReport requires a valid license key.
You can provide it in two ways:

Option 1: Command line argument

Pass the license key directly using the -l or --license option:

alfareport report.js -l XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX

Option 2: License file

Place a plain text file named alfareport.lic in the same directory as the alfareport executable. The file should contain only the license key:

XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX

The license file is automatically detected at startup. This method is useful for automation scripts or when you don't want to type the key every time.

Note: If both the license file and command line parameter are provided, the command line parameter takes precedence.