Search by

typesetterio / typesetter

aaronsaray

The main typesetter service for generating PDFs from Markdown for ebooks.

1.0.0 2026-10-11 01:04 UTC

This package is auto-updated.

Last update: 2026-10-13 16:17:32 UTC


README

Typesetter

License Packagist GitHub Workflow Status

Pages from the Typesetter demo book

This is the Typesetter main service. This can be used in your own projects directly if you want. You probably want to head over to typesetter-cli though.

Install

This requires PHP 8.4 or above.

composer require typesetterio/typesetter

Usage

Build a Config from an array of options, then pass it to Typesetter::generate() to get a PDF binary back from MPDF.

Example:

$config = new \Typesetterio\Typesetter\Config([
    'title' => 'Benjamin Button',
    'author' => 'F. Scott Fitzgerald',
    'theme' => 'bb',
    'content' => 'content',

    'toc-enabled' => true,
    'toc-links' => true,
    'toc-header' => 'Table of Contents',
    'toc-levels' => ['H1', 'H2'],
    'toc-attributes' => ['resetpagenum' => 1],

    'footer' => '{PAGENO}',

    'mpdf' => [
        'fontDir' => ['bb/fonts'],
        'fontdata' => [
            'garamond' => ['R' => 'Garamond.ttf', 'B' => 'Garamond-Bold.ttf', 'I' => 'Garamond-Italic.ttf'],
        ],
    ],

    'markdown-extensions' => ['md', 'markdown'],
    'observers' => [
        new \Typesetterio\Typesetter\Observers\DefaultMarkdownConfiguration(),
        new \Typesetterio\Typesetter\Observers\FirstElementInChapterCssClass(),
        new \Typesetterio\Typesetter\Observers\BreakToPageBreak(),
        new \Typesetterio\Typesetter\Observers\Credits(),
    ],
]);

$service = new \Typesetterio\Typesetter\Typesetter();
$pdfContent = $service->generate($config);
file_put_contents('my-pdf.pdf', $pdfContent);

toc-attributes takes any attribute of mPDF's <tocpagebreak> tag. mpdf takes any option of the mPDF constructor; fontDir and fontdata are added to mPDF's bundled fonts.

To learn more, please check out the documentation. This details configuration, customization, themes and cover generation, observers, listeners and more.

Demo

php demo/run.php generates demo/output.pdf, a book that exercises the library's features and states on each page what it should look like.

Development

Requires PHP 8.4 or newer and Composer. make act additionally needs Docker and act. On macOS, brew install php composer act.

Run make to list the available targets.

Changelog

See CHANGELOG.md.

Credits

This was heavily influenced by the Ibis project but is a complete rewrite.

This package stands on the shoulders of giants like MPDF and the League Commonmark library.

Aaron Saray is the primary author and maintainer.