Ai AgentsApril 04, 2026

How I Built an AI Agent That Generates Professional Invoices

Pressa Team

AI agents can write code, send emails, query databases, and search the web. But ask one to create a professional PDF invoice and it falls apart. It will offer to generate Markdown, suggest a screenshot of an HTML table, or apologize and explain that document generation is outside its capabilities. This is the last mile problem of AI agents: they can do everything except produce the final artifact your business actually needs.

This post walks through building an AI agent that generates publication-quality invoices on demand, using natural language prompts. No templates, no HTML hacks, no Puppeteer. Just a prompt, a compile step, and a perfect PDF.

The Last Mile Problem

Consider what happens when you ask an AI agent to create an invoice today. The agent has all the data: client name, line items, amounts, tax rates. It can calculate totals, format currency, and structure the information perfectly. But the moment you need that information on paper, the agent is stuck.

The typical workarounds are painful. Generate an HTML page and screenshot it. Build a CSV and hope the recipient opens it in Excel. Create a Markdown file that looks decent in a code editor but unprofessional everywhere else. None of these produce a document you would send to a client.

The missing piece is a compilation step. The agent needs a way to take structured content and turn it into a typeset PDF with proper fonts, spacing, alignment, and page layout. That is exactly what Pressa provides.

The Setup

You need two things: a Pressa account (free tier includes 50 compilations per month) and either the CLI tool or the MCP server.

Option 1: CLI installation. Install globally via npm and authenticate:

Terminal
$ npm install -g @pressa/cli
$ pressa auth
# Optional: stores an API key to raise the limits

Option 2: MCP server for Claude Desktop. Add Pressa to your Claude Desktop configuration so the agent can compile PDFs directly:

claude_desktop_config.json
{
"mcpServers": {
"pressa": {
"command": "npx",
"args": ["-y", "@pressa/mcp"]
}
}
}

Either approach gives the AI agent the ability to compile LaTeX into PDFs. The CLI works with any agent framework. The MCP server integrates natively with Claude.

The Natural Language Approach

Here is the key insight: you do not need to know LaTeX. Modern LLMs are exceptionally good at generating it. LaTeX syntax appears in millions of academic papers, textbooks, and technical documents in their training data. Generating a well-structured LaTeX invoice is a trivial task for any capable model.

The workflow is simple. You describe what you want in plain English:

Prompt
Create an invoice for Acme Corp.
Invoice number: INV-2026-0042
Date: April 4, 2026
Due: Net-30

Line items:
- API Integration Setup: $2,400.00 (1x)
- Monthly Platform License: $499.00 (3x)
- Custom Template Design: $850.00 (2x)
- Data Migration Service: $1,200.00 (1x)
- Priority Support Plan: $199.00 (6x)

Tax rate: 8.5%
Use a clean, modern layout with a navy blue header.

The agent takes this prompt, generates a complete LaTeX document with proper table formatting, color definitions, font selections, and page geometry. Then it compiles the result through Pressa. The output is a publication-quality PDF that looks like it came from professional accounting software.

Step by Step: CLI Workflow

When using the CLI, the agent writes LaTeX to a file and compiles it in a single command. Here is what a typical session looks like:

Terminal
# Agent generates LaTeX and writes it to a file
$ cat invoice.tex
\documentclass{article}
\usepackage{geometry, booktabs, xcolor, fancyhdr}
\definecolor{navy}{HTML}{1B2A4A}
...

# One command to compile
$ pressa compile invoice.tex --output invoice.pdf

Compiling invoice.tex...
Done. Output: invoice.pdf (42.3 KB)

The entire process takes a few seconds. The agent writes the file, runs the command, and the PDF appears locally. No LaTeX installation needed on your machine. No Docker containers. No dependency management. Pressa handles all of that server-side.

Step by Step: MCP Workflow

The MCP integration is even more seamless. When Pressa is configured as an MCP server, the agent calls the compile tool directly. No file system interaction needed.

MCP Tool Call
Tool: pressa.compile
Input: {
"latex": "\documentclass{article}\usepackage{geometry, booktabs...}...",
"output_format": "pdf"
}

Result: {
"status": "success",
"download_url": "https://api.pressa.dev/api/v1/downloads/abc123",
"size_bytes": 43315,
"pages": 1
}

The agent generates the LaTeX, passes it directly to the compile tool, and gets back a download URL. The user sees the PDF appear in the conversation. No files to manage, no commands to run. This is the experience that makes AI-generated documents feel native.

Iterating on the Design

This is where the AI agent workflow truly shines. Traditional document generation is rigid: change a template, rebuild, check the output, repeat. With an AI agent and Pressa, iteration is conversational.

After the first invoice is generated, you can refine it with follow-up prompts:

Follow-up Prompts
"Add a 10% early payment discount column."

"Change the header color to match our brand (#2563EB)."

"Add a QR code for bank transfer payment."

"Include our company logo in the top left corner."

"Move the payment terms to the footer and add a thank you note."

Each iteration is a new compile call. The agent modifies the LaTeX, recompiles, and you see the updated PDF in seconds. What would take hours of template editing becomes a five-minute conversation.

The feedback loop is immediate. You describe a change, the agent implements it, Pressa compiles it, and you see the result. No context switching between a code editor, a browser, and a PDF viewer. The entire workflow stays inside your conversation.

Beyond Invoices

The invoice example is compelling because it is concrete, but the pattern is universal. The same agent workflow works for any structured document:

Reports. Feed the agent analytics data and ask for a quarterly business report with charts, tables, and executive summaries.

Contracts. Provide contract terms and let the agent generate a properly formatted legal document with numbered clauses and signature blocks.

Certificates. Generate completion certificates, awards, or credentials with professional typography and layout.

Letters. Create formal correspondence with proper letterhead, formatting, and postal standards.

The examples page shows what Pressa can produce across different document types. Each example was generated using the same pattern: natural language prompt, LaTeX generation, Pressa compilation.

Getting Started

Pressa is free to start. The free tier includes 50 compilations per month, enough to build and test your agent workflow. No credit card required.

The fastest path to your first AI-generated invoice:

1. Create a free account and get your API key.

2. Install the CLI or configure the MCP server.

3. Ask your AI agent to generate an invoice. It already knows LaTeX.

Check the documentation for detailed setup guides, or explore the examples page to see the quality Pressa delivers.

The last mile problem is solved. Your AI agents can finally produce documents that look like a human designed them.

Try Pressa Free

One API call. LaTeX in, PDF out. Professional documents in seconds.