PHPackages                             papier/papier - 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. papier/papier

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

papier/papier
=============

A comprehensive PHP library for generating and reading PDF documents, implementing ISO 32000-1:2008 (PDF 1.7)

v3.0.0(3d ago)2215[1 issues](https://github.com/mikaelcarlavan/papier/issues)MITPHPPHP &gt;=8.1

Since Dec 28Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/mikaelcarlavan/papier)[ Packagist](https://packagist.org/packages/papier/papier)[ Docs](https://papier.io)[ Fund](https://www.buymeacoffee.com/mikaelcarlavan)[ RSS](/packages/papier-papier/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (6)Versions (15)Used By (0)

Papier
======

[](#papier)

 [![Total Downloads](https://camo.githubusercontent.com/9b57d6ff0ada30322513207cb07a8626a4ea27caf55a29e59e10cb3f103a06e2/68747470733a2f2f706f7365722e707567782e6f72672f7061706965722f7061706965722f642f746f74616c2e737667)](https://packagist.org/packages/papier/papier) [![Latest Stable Version](https://camo.githubusercontent.com/23428a9d0894dea89a4daabba41fe550aa1da937aeb29739f6cae710afc6f6db/68747470733a2f2f706f7365722e707567782e6f72672f7061706965722f7061706965722f762f737461626c652e737667)](https://packagist.org/packages/papier/papier) [![License](https://camo.githubusercontent.com/b517e24c868b16acbdd6b697f509db1634674deae7039b67463712298cd65109/68747470733a2f2f706f7365722e707567782e6f72672f7061706965722f7061706965722f6c6963656e73652e737667)](https://packagist.org/packages/papier/papier)

A comprehensive PHP library for generating and reading PDF documents, implementing **ISO 32000-1:2008 (PDF 1.7)**.

Papier was built with the assistance of [Claude](https://claude.ai) (Anthropic's AI assistant), which helped design the API, implement the PDF specification, and write the examples throughout the library.

Requirements
------------

[](#requirements)

- PHP 8.1+
- Extensions: `ext-zlib`, `ext-mbstring`, `ext-openssl`

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

[](#installation)

```
composer require papier/papier
```

What you can do
---------------

[](#what-you-can-do)

### Create documents

[](#create-documents)

```
use Papier\PdfDocument;

$doc = PdfDocument::create();
$doc->setTitle('My Document')
    ->setAuthor('Jane Doe')
    ->setSubject('A sample PDF');

$page = $doc->addPage();          // A4 by default
$doc->save('output.pdf');
```

### Text and typography

[](#text-and-typography)

Add text with fonts, sizes, colours, and opacity. Latin characters (é, à, ü, ñ, …) work out of the box.

```
use Papier\Elements\{Color, Text, TextBox};

$font = $doc->addFont('Helvetica');
$bold = $doc->addFont('Helvetica-Bold');

$page->add(
    Text::write('Bonjour, Ré!')->at(72, 750)->font($bold, 24)->color(Color::hex('#1a1a2e')),
    TextBox::write('Un paragraphe avec retour à la ligne automatique.')
        ->at(72, 700)->size(450, 80)
        ->font($font, 12)
        ->lineHeight(1.5),
);
```

### Embedded TrueType / OpenType fonts

[](#embedded-truetype--opentype-fonts)

```
$lato = $doc->addFont(__DIR__ . '/Lato-Regular.ttf');

$page->add(
    Text::write('Lato at 18 pt')->at(72, 680)->font($lato, 18),
);
```

Papier extracts the PostScript name from the font's `name` table, parses metrics from `hhea` / `OS/2` / `hmtx`, and embeds the full font program as `FontFile2`.

### Images

[](#images)

Load JPEG or PNG images from a file path — type is auto-detected:

```
use Papier\Elements\Image;

$page->add(
    Image::fromFile(__DIR__ . '/photo.png')->at(72, 500)->fitWidth(300),
);
```

Or from raw bytes if you already have them in memory:

```
Image::fromJpeg(file_get_contents('photo.jpg'))->at(72, 400)->size(200, 150)->opacity(0.8),
Image::fromPng(file_get_contents('logo.png'))->at(300, 400)->fitHeight(60),
```

PNG alpha channels are handled automatically via an SMask XObject.

### Graphics

[](#graphics)

Rectangles, circles, lines, curves, complex paths, gradients, patterns, and clipping:

```
use Papier\Elements\{Circle, Line, Rectangle};

$page->add(
    Rectangle::create(72, 400, 200, 100)->fill(Color::rgb(0.2, 0.5, 0.9))->stroke(Color::black(), 1.5),
    Circle::create(400, 450, 50)->fill(Color::hex('#e74c3c')),
    Line::from(72, 380)->to(523, 380)->color(Color::gray(0.5))->width(0.5),
);
```

For lower-level control use `ContentStream` directly (PDF operators: `re`, `m`, `l`, `c`, `Tf`, `Tj`, …).

### Tables

[](#tables)

```
use Papier\Elements\Table;

$table = Table::create(430, [100, 150, 180])
    ->at(72, 700)
    ->header(['Name', 'Role', 'Email'], $bold)
    ->row(['Alice', 'Engineer', 'alice@example.com'])
    ->row(['Bob',   'Designer', 'bob@example.com']);

$page->add($table);
```

Features: column widths, header/footer rows, row/cell colours, padding, border control per side, `rowspan`, vertical alignment, opacity.

### Interactive forms (AcroForm)

[](#interactive-forms-acroform)

```
use Papier\AcroForm\{AcroForm, TextField, CheckboxField, ComboBoxField};

$form = new AcroForm();

$name = new TextField('person.name');
$name->setRect(200, 700, 400, 718)
     ->setDefaultAppearance($font, 12)
     ->setValue('Alice');
$form->addField($name);

$doc->setAcroForm($form);
```

Supported field types: `TextField`, `CheckboxField`, `RadioButtonField`, `ComboBoxField`, `ListBoxField`, `SignatureField`.

### Annotations

[](#annotations)

```
use Papier\Annotation\{HighlightAnnotation, LinkAnnotation, StampAnnotation};
use Papier\Elements\Color;

$link = new LinkAnnotation(72, 680, 272, 700);
$link->setURI('https://example.com')->setBorderStyle(0);
$page->addAnnotation($link);

$stamp = new StampAnnotation(390, 555, 520, 605);
$stamp->setIcon('Draft')->setColor(Color::rgb(1, 0, 0));
$page->addAnnotation($stamp);
```

13 annotation subtypes: `TextAnnotation`, `LinkAnnotation`, `FreeTextAnnotation`, `HighlightAnnotation`, `UnderlineAnnotation`, `StrikeOutAnnotation`, `SquigglyAnnotation`, `LineAnnotation`, `SquareAnnotation`, `CircleAnnotation`, `PolygonAnnotation`, `StampAnnotation`, `InkAnnotation`.

### Bookmarks (outlines)

[](#bookmarks-outlines)

```
use Papier\Structure\PdfOutline;

$outline = new PdfOutline();
$ch1 = $outline->addItem('Chapter 1', $page1);
$ch1->addChild('Section 1.1', $page2);
$doc->setOutline($outline);
```

### Document-level features

[](#document-level-features)

```
// Named destinations and open action
$doc->addNamedDestination('intro', $page, 72, 750);
$doc->setOpenDestination($page, 0, 841);

// Page labels (Roman numerals, letters, custom prefix…)
use Papier\Structure\PageLabelStyle;
$doc->addPageLabel(0, PageLabelStyle::RomanLower);              // i, ii, iii, …
$doc->addPageLabel(4, PageLabelStyle::Decimal);                 // 1, 2, 3, …
$doc->addPageLabel(4, PageLabelStyle::Decimal, prefix: 'p.');   // p.1, p.2, …

// File attachments
$doc->attachFile('data.json', file_get_contents('data.json'), 'application/json');

// Password protection and permissions
use Papier\Encryption\PdfEncryption;
$enc = new PdfEncryption();
$enc->setUserPassword('user')->setOwnerPassword('owner');
$doc->setEncryption($enc);
```

### Optional content (layers)

[](#optional-content-layers)

```
use Papier\OptionalContent\{OCGroup, OCProperties};

$bg   = new OCGroup('Background');
$text = new OCGroup('Text');

$ocProps = new OCProperties();
$ocProps->addOCG($bg)->addOCG($text)
        ->setDefaultConfig('Default', on: [$bg, $text]);
$doc->setOCProperties($ocProps);
```

Wrap content in `ContentStream::beginMarkedContentProps('OC', …) / endMarkedContent()` to bind it to a layer.

### Multimedia

[](#multimedia)

```
use Papier\Multimedia\{MediaRendition, MediaPlayParams};
use Papier\Annotation\ScreenAnnotation;

$params = (new MediaPlayParams())->setVolume(80)->setAutoPlay(true)->setShowControls(true);
$rendition = new MediaRendition('video/mp4', 'demo.mp4');
$rendition->setPlayParams($params);

$screen = new ScreenAnnotation(72, 400, 372, 600);
$screen->setRendition($rendition);
$page->addAnnotation($screen);
```

### Page transitions

[](#page-transitions)

```
use Papier\Structure\PageTransition;

$page->setTransition((new PageTransition())->setStyle('Fly')->setDuration(1.0));
```

### Read and parse existing PDFs

[](#read-and-parse-existing-pdfs)

```
use Papier\Parser\PdfParser;

$parser = new PdfParser('document.pdf');

echo $parser->getPageCount();                  // number of pages
echo $parser->extractText();                   // all text content
echo $parser->extractTextFromPageNumber(1);    // page 1 only
print_r($parser->getFonts());                  // font list
print_r($parser->getAnnotations());            // annotations
print_r($parser->extractImages());             // embedded images
print_r($parser->getPageInfo(1));              // page dimensions, resources
print_r($parser->getMetadata());               // title, author, subject, …
```

Examples
--------

[](#examples)

The `examples/` directory contains 15 runnable scripts:

FileDemonstrates`01_hello_world.php`Minimal document creation`02_text_formatting.php`Fonts, sizes, colours, alignment`03_graphics.php`Paths, shapes, gradients, clipping`04_images.php`JPEG/PNG embedding, `fromFile()`, alpha, scaling`05_forms.php`AcroForm fields`06_annotations.php`All 13 annotation subtypes`07_bookmarks_and_encryption.php`Outlines, password protection`08_advanced_graphics.php`Patterns, shadings, transparency groups`09_read_pdf.php`Parsing an existing PDF`10_optional_content_layers.php`Togglable layers`11_elements.php`High-level element API`12_multimedia.php`Embedded audio/video`13_transitions_and_media_elements.php`Page transitions`14_table.php`Tables with rowspan, footer, per-cell borders`15_ttf_fonts.php`Embedding TTF/OTF font filesRun any example:

```
php examples/01_hello_world.php
```

Output PDFs are written to `examples/output/`.

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

[](#architecture)

```
src/
├── PdfDocument.php           Entry point — document, pages, fonts, metadata
├── Elements/                 High-level fluent API (Text, TextBox, Image, Table, …)
├── Content/ContentStream.php Low-level PDF operators
├── Annotation/               13 annotation types
├── AcroForm/                 Interactive form fields
├── Font/                     Type1, TrueType, Type0/CID, font descriptors
├── Structure/                Pages, outlines, resources, transitions
├── OptionalContent/          Layers (OCG / OCProperties)
├── Multimedia/               Renditions, media play parameters
├── Encryption/               RC4 / AES password protection
├── Parser/                   PDF parser and text extractor
└── Writer/                   Low-level binary PDF writer

```

Licence
-------

[](#licence)

Papier is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance92

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~42 days

Recently: every ~18 days

Total

14

Last Release

3d ago

Major Versions

v1.4.2 → v2.0.02026-04-19

v2.1.0 → v3.0.02026-07-01

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10746841?v=4)[Mikael Carlavan](/maintainers/mikaelcarlavan)[@mikaelcarlavan](https://github.com/mikaelcarlavan)

---

Top Contributors

[![mikaelcarlavan](https://avatars.githubusercontent.com/u/10746841?v=4)](https://github.com/mikaelcarlavan "mikaelcarlavan (569 commits)")

---

Tags

pdfpdf-generationphpphp-librarypdfPDF GENERATORPDF Readeriso32000pdf17

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.4k99.4M384](/packages/barryvdh-laravel-dompdf)[tecnickcom/tcpdf

Deprecated legacy PDF engine for PHP. Use instead tecnickcom/tc-lib-pdf.

4.5k109.8M579](/packages/tecnickcom-tcpdf)[mpdf/mpdf

PHP library generating PDF files from UTF-8 encoded HTML

4.7k83.4M565](/packages/mpdf-mpdf)[knplabs/knp-snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.

4.5k72.4M62](/packages/knplabs-knp-snappy)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k36.7M156](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k40.5M272](/packages/smalot-pdfparser)

PHPackages © 2026

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