PHPackages                             mohammadraufzahed/folio - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. mohammadraufzahed/folio

ActiveLibrary[Templating &amp; Views](/categories/templating)

mohammadraufzahed/folio
=======================

Modern PDF generation library for PHP 8.3+ with composable document model, layout engine, and custom template language

2.0.3(1mo ago)013↓75%MITPHPPHP &gt;=8.3CI passing

Since Jul 15Pushed 1mo agoCompare

[ Source](https://github.com/mohammadraufzahed/folio)[ Packagist](https://packagist.org/packages/mohammadraufzahed/folio)[ Docs](https://mohammadraufzahed.github.io/folio/)[ RSS](/packages/mohammadraufzahed-folio/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (7)Dependencies (6)Versions (16)Used By (0)

Folio PDF
=========

[](#folio-pdf)

A modern, production-quality PDF generation library for PHP 8.3+.

> Flutter / SwiftUI / Jetpack Compose for PDFs.

Folio PDF implements its own document model, layout engine, templating engine, and PDF renderer - no wrapping of HTML-to-PDF solutions. It provides a composable, immutable design with a fluent builder API and a custom template language for declarative PDF generation.

Features
--------

[](#features)

- **PHP 8.3+** with strict types everywhere
- **Zero Runtime Dependencies** - pure PHP implementation
- **Composable Document Model** - immutable nodes with fluent builder API
- **Custom Template Language** - declarative syntax with data binding
- **Layout Engine** - flex and grid layouts with automatic pagination
- **Comprehensive Styling** - colors, fonts, borders, shadows, spacing
- **Table Support** - simple, nested, multi-header, and multi-level tables
- **Page Chrome** - themed headers and footers with page numbers
- **Developer Tooling** - LSP, VS Code extension, formatter, tree-sitter grammar

Installation
------------

[](#installation)

Install via Composer:

```
composer require folio/pdf
```

### Requirements

[](#requirements)

- PHP 8.3 or higher
- Composer for dependency management
- No external dependencies or extensions required

Quick Start
-----------

[](#quick-start)

### PHP Builder API

[](#php-builder-api)

```
use Folio\Pdf\Document\Pdf;
use Folio\Pdf\Nodes\Column;
use Folio\Pdf\Nodes\Heading;
use Folio\Pdf\Nodes\Page;
use Folio\Pdf\Nodes\Text;
use Folio\Pdf\Styling\Color;
use Folio\Pdf\Styling\Style;

Pdf::make()
    ->page(
        Page::a4()->withContent(
            Column::make()
                ->addChildren([
                    Heading::h1('Invoice'),
                    Text::make('Customer: John Doe'),
                    Text::make('Amount: $100.00'),
                ])
        )
    )
    ->save('invoice.pdf');
```

### Template Language

[](#template-language)

```
var title = "Invoice"
var customer = "John Doe"

page {
  heading title
  text "Customer: " customer
  text "Amount: $100.00"
}

```

```
use Folio\Pdf\Template\PhpTemplateCompiler;

$compiler = new PhpTemplateCompiler();
$pdf = $compiler->renderFile('invoice.folio', [
    'title' => 'Invoice',
    'customer' => 'John Doe',
]);
$pdf->save('invoice.pdf');
```

Documentation
-------------

[](#documentation)

Full documentation is available at [mohammadraufzahed.github.io/folio](https://mohammadraufzahed.github.io/folio)

- [Getting Started](https://mohammadraufzahed.github.io/folio/guide/getting-started) - Installation and basic usage
- [API Reference](https://mohammadraufzahed.github.io/folio/api/pdf) - Complete API documentation
- [Template Language](https://mohammadraufzahed.github.io/folio/template-language/overview) - Template syntax and features
- [Examples](https://mohammadraufzahed.github.io/folio/examples) - Real-world usage examples
- [Tooling](https://mohammadraufzahed.github.io/folio/tooling/formatter) - LSP, formatter, and VS Code extension

Architecture
------------

[](#architecture)

Folio PDF is built with a clean, modular architecture:

- **Document Model** - Immutable AST nodes (Page, Column, Row, Text, Table, etc.)
- **Layout Engine** - Flex and grid layout calculations with automatic pagination
- **Template Compiler** - Lexer, parser, and PHP code generator for templates
- **Styling System** - Comprehensive style properties with type safety
- **PDF Writer** - Direct PDF generation without external dependencies

Key Concepts
------------

[](#key-concepts)

### Immutable Design

[](#immutable-design)

All document nodes are immutable. Methods like `withStyle()` return new instances:

```
$page = Page::a4();
$styledPage = $page->withContent($content); // Returns new instance
```

### Composable Layouts

[](#composable-layouts)

Build complex layouts from simple components:

```
Column::make()
    ->addChildren([
        Heading::h2('Section 1'),
        Text::make('Content here'),
        Row::make()->addChildren([
            Text::make('Left'),
            Text::make('Right'),
        ]),
    ])
```

### Styling

[](#styling)

Apply styles with a fluent API:

```
Style::make()
    ->withPadding(20.0)
    ->withColor(Color::hex('#333333'))
    ->withFontSize(14.0)
    ->withFontWeight(FontWeight::Bold)
```

Examples
--------

[](#examples)

See the `examples/` directory for complete working examples:

- `hello-world.php` - Basic PDF generation
- `invoice.php` - Invoice with tables and styling
- `company-report.php` - Multi-page document with headers/footers
- `tables.php` - Various table configurations

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
composer test
```

### Static Analysis

[](#static-analysis)

```
composer analyze
```

### Code Style

[](#code-style)

Follow PSR-12 coding standards. Use strict types and type hints throughout.

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

- Report bugs via [GitHub Issues](https://github.com/mohammadraufzahed/folio/issues)
- Submit pull requests for improvements
- Discuss features in [GitHub Discussions](https://github.com/mohammadraufzahed/folio/discussions)

Security
--------

[](#security)

For security vulnerabilities, please email  instead of using public issues. See [SECURITY.md](SECURITY.md) for details.

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) file for details.

Acknowledgments
---------------

[](#acknowledgments)

- Inspired by Flutter, SwiftUI, and Jetpack Compose design patterns
- Built with modern PHP 8.3+ features
- Community-driven open-source project

Links
-----

[](#links)

- [Documentation](https://mohammadraufzahed.github.io/folio)
- [GitHub Repository](https://github.com/mohammadraufzahed/folio)
- [Packagist](https://packagist.org/packages/folio/pdf)
- [Report Issues](https://github.com/mohammadraufzahed/folio/issues)

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance91

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

9

Last Release

44d ago

Major Versions

1.1.3 → 2.0.02026-07-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24861953?v=4)[Mohammad Raufzahed](/maintainers/mohammadraufzahed)[@mohammadraufzahed](https://github.com/mohammadraufzahed)

---

Top Contributors

[![devin-ai-integration[bot]](https://avatars.githubusercontent.com/in/811515?v=4)](https://github.com/devin-ai-integration[bot] "devin-ai-integration[bot] (44 commits)")[![mohammadraufzahed](https://avatars.githubusercontent.com/u/24861953?v=4)](https://github.com/mohammadraufzahed "mohammadraufzahed (22 commits)")

---

Tags

composerformatterimmutablelanguage-serverlayout-enginemit-licenseopen-sourcepackagistpdfpdf-generationpdf-rendererphppsr-4template-languagetemplatingtree-sittervscodepdfgeneratortemplatereportlayoutdocument

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mohammadraufzahed-folio/health.svg)

```
[![Health](https://phpackages.com/badges/mohammadraufzahed-folio/health.svg)](https://phpackages.com/packages/mohammadraufzahed-folio)
```

###  Alternatives

[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

240104.0k](/packages/anourvalar-office)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
