PHPackages                             kallefrombosnia/tinypdf-php - 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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. kallefrombosnia/tinypdf-php

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

kallefrombosnia/tinypdf-php
===========================

Minimal PDF creation library for PHP 8.2+. Zero dependencies, strongly typed, clean code.

v1.1.0(4mo ago)250MITPHPPHP &gt;=8.2CI passing

Since Jan 5Pushed 4mo agoCompare

[ Source](https://github.com/kallefrombosnia/tinypdf-php)[ Packagist](https://packagist.org/packages/kallefrombosnia/tinypdf-php)[ RSS](/packages/kallefrombosnia-tinypdf-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

TinyPDF-PHP
===========

[](#tinypdf-php)

 [![TinyPDF-PHP Preview](art/preview.png)](art/preview.png)

[![Tests](https://github.com/kallefrombosnia/tinypdf-php/actions/workflows/tests.yml/badge.svg)](https://github.com/kallefrombosnia/tinypdf-php/actions/workflows/tests.yml)[![Issues](https://camo.githubusercontent.com/5755d403331fb25eeb1a4316bfddced53fbfdfbeff9ccbaf71a6cd54c399c341/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6b616c6c6566726f6d626f736e69612f74696e797064662d7068702e7376673f7374796c653d666c61742d737175617265)](https://github.com/kallefrombosnia/tinypdf-php/issues)

Minimal PDF creation library for PHP 8.2+. Zero dependencies, strongly typed, clean code architecture.

Port of [tinypdf](https://github.com/Lulzx/tinypdf) from TypeScript to PHP.

Features
--------

[](#features)

- Create PDFs from scratch with zero dependencies
- Strongly typed with PHP 8.2+ type declarations
- Clean architecture with interfaces and value objects
- Support for text, rectangles, lines, JPEG images, and clickable links
- Built-in markdown to PDF conversion
- Text measurement and alignment
- Color support (hex format)

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

[](#installation)

```
composer require kallefrombosnia/tinypdf-php
```

Usage
-----

[](#usage)

### Basic PDF Creation

[](#basic-pdf-creation)

```
use TinyPdf\TinyPdf;
use TinyPdf\TextOptions;
use TinyPdf\TextAlign;

$pdf = TinyPdf::create();

// Add a page (default US Letter: 612x792 points)
$pdf->page(function ($ctx) {
    // Add text
    $ctx->text('Hello World!', 50, 700, 24);

    // Text with options
    $ctx->text(
        'Centered text',
        50,
        650,
        16,
        new TextOptions(
            align: TextAlign::CENTER,
            width: 500,
            color: '#0066cc'
        )
    );

    // Draw a rectangle
    $ctx->rect(50, 600, 200, 100, '#ffcc00');

    // Draw a line
    $ctx->line(50, 580, 250, 580, '#000000', 2);
});

// Custom page size
$pdf->page(595, 842, function ($ctx) { // A4 size
    $ctx->text('A4 Page', 50, 700, 18);
});

// Build and save
$pdfContent = $pdf->build();
file_put_contents('output.pdf', $pdfContent);
```

### Adding Images

[](#adding-images)

```
$pdf = TinyPdf::create();

$pdf->page(function ($ctx) {
    $jpegData = file_get_contents('image.jpg');
    $ctx->image($jpegData, 50, 500, 200, 150);
});

file_put_contents('output.pdf', $pdf->build());
```

### Markdown to PDF

[](#markdown-to-pdf)

```
use TinyPdf\MarkdownConverter;

$markdown = page(function ($ctx) {
    $ctx->text('GitHub Repository', 50, 700, 12, new TextOptions(color: '#0066cc'));
    $ctx->link('https://github.com/kallefrombosnia/tinypdf-php', 50, 695, 115, 20, new LinkOptions(underline: '#0066cc'));

    $ctx->text('Check out Webflow agency', 50, 650, 12, new TextOptions(color: '#95a5a6'));
    $ctx->link('https://www.flowout.com/', 50, 645, 150, 20);
});

file_put_contents('output.pdf', $pdf->build());
```

### Text Measurement

[](#text-measurement)

```
use TinyPdf\TinyPdf;

$width = TinyPdf::measureText('Hello World', 24);
echo "Text width: {$width} points\n";
```

Examples
--------

[](#examples)

The library includes several complete examples in the `examples/` directory:

### Running Examples

[](#running-examples)

Run all examples at once:

```
php example.php
```

Or run individual examples:

```
# Basic text and shapes
php examples/basic/basic.php

# Professional invoice
php examples/invoice/invoice.php

# Markdown to PDF
php examples/markdown/markdown.php

# Multi-page document
php examples/multipage/multipage.php
```

### Available Examples

[](#available-examples)

Each example includes its own README with detailed information and generated PDF output.

- **[Basic](examples/basic/)** - Text rendering, shapes, colors, alignment, and links ([preview](examples/basic/output.pdf))
- **[Invoice](examples/invoice/)** - Professional invoice template ([preview](examples/invoice/output.pdf))
- **[Receipt](examples/receipt/)** - Sales receipt template ([preview](examples/receipt/output.pdf))
- **[Report](examples/report/)** - Business report with charts ([preview](examples/report/output.pdf))
- **[Shipping Label](examples/shipping-label/)** - Package shipping label ([preview](examples/shipping-label/output.pdf))
- **[Markdown](examples/markdown/)** - Convert markdown to PDF ([preview](examples/markdown/output.pdf))
- **[Multi-Page](examples/multipage/)** - Multi-page documents ([preview](examples/multipage/output.pdf))
- **[Ticket](examples/ticket/)** - Event ticket design ([preview](examples/ticket/output.pdf))
- **[Data Export](examples/data-export/)** - Export data tables ([preview](examples/data-export/output.pdf))
- **[Service Agreement](examples/service-agreement/)** - Contract template ([preview](examples/service-agreement/output.pdf))

API Reference
-------------

[](#api-reference)

For detailed API documentation, see the inline documentation in the source code:

- [TinyPdf](src/TinyPdf.php) - Main factory class
- [PageContextInterface](src/Contracts/PageContextInterface.php) - Drawing operations (text, rect, line, image, link)
- [TextOptions](src/TextOptions.php) - Text rendering options
- [LinkOptions](src/LinkOptions.php) - Link configuration
- [MarkdownConverter](src/MarkdownConverter.php) - Markdown to PDF conversion

Coordinate System
-----------------

[](#coordinate-system)

PDF uses a coordinate system where:

- Origin (0, 0) is at the bottom-left corner
- X increases to the right
- Y increases upward
- Units are in points (1/72 inch)

Common page sizes:

- US Letter: 612 x 792 points
- A4: 595 x 842 points

Testing &amp; Quality
---------------------

[](#testing--quality)

```
composer test              # Run all tests
composer test:coverage     # Run tests with coverage
composer phpstan          # Run static analysis
```

**77 tests** with comprehensive coverage including unit tests, architecture tests, and integration tests.

For detailed information about the test suite, coverage, and quality standards, see [tests/README.md](tests/README.md).

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

This is a PHP port of [tinypdf](https://github.com/Lulzx/tinypdf) by Lulzx.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance77

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

2

Last Release

126d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e4b0c1c0045ccf51164668df3dd963f1ce3679d7b28213332056dda5baf31e7c?d=identicon)[kallefrombosnia](/maintainers/kallefrombosnia)

---

Top Contributors

[![kallefrombosnia](https://avatars.githubusercontent.com/u/30219259?v=4)](https://github.com/kallefrombosnia "kallefrombosnia (6 commits)")

---

Tags

documentmarkdownpdfphptinypdfpdfmarkdowndocumentpdf-generationtinypdf

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kallefrombosnia-tinypdf-php/health.svg)

```
[![Health](https://phpackages.com/badges/kallefrombosnia-tinypdf-php/health.svg)](https://phpackages.com/packages/kallefrombosnia-tinypdf-php)
```

###  Alternatives

[tecnickcom/tc-lib-pdf

PHP PDF Library

1.8k452.3k7](/packages/tecnickcom-tc-lib-pdf)[gotenberg/gotenberg-php

A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!

3685.2M19](/packages/gotenberg-gotenberg-php)[themsaid/ibis

Markdown to PDF book builder

2.0k2.0k](/packages/themsaid-ibis)[tecnickcom/tc-lib-pdf-parser

PHP library to parse PDF documents

4092.8k](/packages/tecnickcom-tc-lib-pdf-parser)[scannerjs/scanner.js

ScannerJS: JavaScript web scan JPG PDF images from TWAIN WIA scanners in browser (Chrome, Edge, Firefox or IE)

5914.3k](/packages/scannerjs-scannerjs)[popphp/pop-pdf

PHP PDF library for generating and importing PDF documents. A component of the Pop PHP Framework

207.8k1](/packages/popphp-pop-pdf)

PHPackages © 2026

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