Agents are tired of just talking. They want to print. Nayan Kunwar has dropped Lekhan, a new agent skill that enables AI assistants to generate print-ready PDFs directly from HTML and CSS templates. The tool leverages headless Chromium to render documents, ensuring that the final output matches the web-based design intent perfectly. This isn't just a wrapper; it's a full pipeline for layout verification.
The Pipeline: HTML to PNG Verification
Lekhan operates by writing a self-contained HTML and CSS document, which is then printed using headless Chromium. The critical innovation here is the verification step: the script exports one PNG per page. This allows the agentβor the human operatorβto visually inspect the layout before finalizing the file. It supports complex requirements like multi-page technical guides, dense rΓ©sumΓ©s, and data reports with running page numbers.
Technical Implementation and Dependencies
The system requires Python 3.10+ and Playwright. Installation involves a standard pip setup for dependencies like pypdf, pypdfium2, and markdown. If pypdfium2 is missing, the script falls back to pdftoppm from Poppler. The repository includes six sample projects, ranging from a 4-page technical guide with inline SVG diagrams to a landscape certificate. Each sample folder contains the source HTML, the finished PDF, and a preview PNG, proving the system's capability with fictional but realistic data.
Integration with Major Agent Frameworks
Kunwar designed Lekhan for broad compatibility with the current agent ecosystem. It integrates seamlessly with OpenCode, Codex, and Claude Code. Users can install the skill globally or per-project using git clone commands, placing the folder in the respective skills directory (e.g., ~/.config/opencode/skills/lekhan). Alternatively, it can be added via the skills CLI using npx skills add nayan-kunwar/lekhan-pdf-skill. The tool respects SKILL.md protocols, instructing agents to plan pages, fill templates, render, and inspect every PNG before delivery.
Key Takeaways
- Visual QA Loop: Agents can now see their own work via page-by-page PNG exports, reducing layout errors.
- Broad Compatibility: Native support for OpenCode, Codex, and Claude Code via standard skill directory conventions.
- Template-Driven Design: Uses explicit .page boxes in CSS for precise control over multi-page documents like reports and certificates.
- Markdown Support: Includes a quick path for converting plain Markdown notes into styled PDFs without manual HTML editing.
The Bottom Line
Lekhan finally closes the loop on AI-generated documents by giving agents the ability to visually verify their output. It transforms PDF generation from a black-box export into a debuggable, iterative design process.