The Complete Production SOP: How to Deploy and Run borb Declarative Python PDF Creator in Autonomous AI Agents
Step-by-step SOP to install and run borb Declarative Python PDF Creator in Codex, Claude Code, and Cursor. Includes verified prompts, layouts, and error fixes.
Technical Overview & Architectural Context
Generating dynamic, pixel-perfect PDF documents with autonomous AI agents often leads to fragile, unmaintainable code when relying on low-level drawing primitives like ReportLab canvas coordinates or raw FPDF scripts. LLMs routinely hallucinate absolute coordinate math, resulting in clipped margins, overlapping multiline text, and broken cross-page table splits. In complex document layouts requiring barcode integration, nested grid structures, and responsive spacing, manual coordinate tracking collapses agent context windows under repetitive self-correction loops. The borb Declarative Python PDF Creator skill constrains autonomous agents to high-level declarative paradigms inspired by modern CSS flexbox and tabular grid management. By enforcing structured PageLayout interfaces (such as SingleColumnLayout and FlexibleGrid) and strongly typed borb document elements, this skill eliminates floating-point coordinate calculations entirely. Coding agents in Codex, Claude Code, Cursor, and Windsurf can reliably generate multi-page financial reports, invoices, and shipping labels containing Barcode/QR widgets that render deterministically every time.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the borb declarative skill into runtime-specific agent configuration directories.
Autonomous runtimes like Claude Code, Cursor, and Windsurf discover deterministic agent behaviors through localized skill manifests. Injecting SKILL.md into either workspace-relative (.agents/skills) or user-level configuration directories ensures the agent recognizes exact triggers for declarative PDF compilation, layout rules, and output serialization without re-prompting.
mkdir -p .agents/skills/borb-declarative-pdf-creator && curl -fsSL https://askills.dev/api/skills/borb-declarative-pdf-creator/raw -o .agents/skills/borb-declarative-pdf-creator/SKILL.md---
name: "borb-declarative-pdf-creator"
description: "Create complex PDF documents using pure Python declarative components and layouts."
metadata:
author: "Joris Schellekens"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "create pdf with borb python"
- "generate barcode in pdf borb"
- "use grid layout borb pdf"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# borb Declarative Python PDF Creator SOP
Always structure documents using Document() -> Page() -> PageLayout. Never calculate raw (x,y) coordinates.Keep the SKILL.md file lean by relying on frontmatter triggers. This avoids consuming agent context tokens with boilerplate layout specifications before the user requests a PDF task.
Ensure that the agent sandbox possesses workspace write permissions (`fs_write: workspace`) so the target PDF binary can be written to disk without triggering access violations.
Environment Secrets & Dependency Validation
Prepare the Python environment with required dependencies and verify borb engine imports.
Borb requires specific image rendering and cryptographic packaging backends. Autonomous agents must verify that dependencies such as Pillow and cryptography are cleanly resolved in the active virtual environment before attempting to generate PDFs or embed QR codes.
python -m venv .venv && source .venv/bin/activate && pip install "borb>=2.1.18" pytestimport sys
try:
import borb
from borb.pdf import Document, Page, SingleColumnLayout, PDF
print(f"borb {borb.__version__} initialized successfully on Python {sys.version.split()[0]}.")
except ImportError as err:
sys.stderr.write(f"Missing borb dependency: {err}\n")
sys.exit(1)Pin the borb version strictly in requirements.txt or pyproject.toml to prevent minor API breaking changes between borb 2.0.x and 2.1.x versions.
Avoid installing borb globally on system Python. On modern Linux distros (PEP 668), missing virtual environment activation will fail with an externally-managed-environment error.
Intent Matching & Trigger Invocation
Engage the skill using strict declarative instructions and verified trigger phrases.
Provide the agent with explicit declarative instructions matching one of the frontmatter triggers (`create pdf with borb python`, `generate barcode in pdf borb`, or `use grid layout borb pdf`). The agent loads the declarative composition rules, instantiates Document and PageLayout instances, and streams elements cleanly without coordinate calculations.
from decimal import Decimal
from pathlib import Path
from borb.pdf import Document, Page, SingleColumnLayout, Paragraph, Barcode, BarcodeType, PDF
from borb.pdf.canvas.color.color import HexColor
def build_invoice(dest_path: Path):
doc = Document()
page = Page()
doc.add_page(page)
layout = SingleColumnLayout(page)
layout.add(Paragraph("INVOICE #98214", font_size=Decimal(18), font_color=HexColor("#1a202c")))
layout.add(Paragraph("Declarative PDF generated via borb-declarative-pdf-creator"))
layout.add(Barcode(data="https://askills.dev/skills/borb-declarative-pdf-creator", type=BarcodeType.QR, width=Decimal(128), height=Decimal(128)))
with open(dest_path, "wb") as pdf_out:
PDF.dumps(pdf_out, doc)
if __name__ == "__main__":
build_invoice(Path("output_invoice.pdf"))Ensure all dimensions, font sizes, and paddings are passed as `Decimal` types rather than raw Python floats to comply with borb's high-precision PDF coordinate engine.
Do not invoke `PDF.dumps()` on a file path string directly. Always open the destination in binary write mode (`open(dest_path, 'wb')`) and pass the file-like object.
Verification, Linting & Output Quality Gate
Execute automated document structure validation to ensure standard PDF compliance.
Enforce quality gates by running automated verification checks before accepting generated output. Borb includes native inspection tools, and agents should run validation scripts to confirm the generated document is structurally sound, contains expected elements, and parses cleanly.
python -c "from borb.pdf import PDF; doc = PDF.loads(open('output_invoice.pdf', 'rb')); assert len(doc.get_pages()) > 0; print('PDF Quality Gate Passed: Valid document tree.')"import pytest
from pathlib import Path
from borb.pdf import PDF
def test_invoice_pdf_integrity(tmp_path):
from generate_invoice import build_invoice
target = tmp_path / "test.pdf"
build_invoice(target)
assert target.exists()
assert target.stat().st_size > 0
with open(target, "rb") as f:
loaded = PDF.loads(f)
assert len(loaded.get_pages()) == 1Always verify file size and page count inside a temporary pytest sandbox fixture before promoting generated PDFs to shared storage.
Always close the read stream when using `PDF.loads()`, or wrap it in a context manager to prevent open file locks on Windows environments.
Real-World Scenario: Automated Multi-Asset Inventory Sheet with QR Codes and FlexibleGrid
“Use grid layout borb pdf to create a 2-column inventory document in Python. Each inventory card must have the asset name, stock quantity, and an embedded QR code linking to the asset SKU. Output to inventory_report.pdf.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent passed Python native floats to widget parameters (such as font_size, padding, or width) instead of Decimal instances.
from decimal import Decimal
# Incorrect: layout.add(Paragraph('Hello', font_size=12.5))
# Correct:
layout.add(Paragraph('Hello', font_size=Decimal('12.5')))Root Cause: PDF.dumps expects a writable binary stream (file-like object or BytesIO), not a string path.
with open(output_path, 'wb') as pdf_file_handle:
PDF.dumps(pdf_file_handle, document)Frequently Asked Questions (borb Declarative Python PDF Creator SOP)
Q:Can I use borb Declarative Python PDF Creator across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. When placed in your workspace or user skill directory, Claude Code, Codex, Cursor, and Windsurf detect the YAML frontmatter triggers and declarative constraints equally.
Q:How does borb Declarative Python PDF Creator prevent context window overflow during long agent sessions?
Traditional PDF generation with libraries like ReportLab causes agents to get trapped in iterative coordinate adjustment loops, consuming thousands of tokens re-centering elements. Borb uses an automated box-model layout engine (like CSS Flexbox), freeing the agent from coordinate math and drastically reducing prompt corrections.
Q:Does this skill require escalated root or container permissions?
No. The skill is rated 98/100 on safety. It operates entirely within standard workspace filesystem permissions (`fs_write: workspace`) with zero shell execution and no network access required at runtime.
Ready to equip your autonomous agent with borb Declarative Python PDF Creator?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.