Skip to content

mprince2k18/typesetter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Packagist Downloads Github Workflow Status

Typesetter

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.1 or above.

composer require typesetterio/typesetter

Usage

Create a config array and pass that to the config maker. Then create a new instance of the Typesetter class. Call the generate method with your config to get a PDF binary return from MPDF.

Example:

$config = [
    'title' => 'Benjamin Button',
    'author' => 'F. Scott Fitzgerald',
    'theme' => 'bb',

    'toc-enabled' => true,
    'toc-links' => true,
    'toc-header' => 'Table of Contents',

    'footer' => '{PAGENO}',

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

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

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

Credits

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

This package stands on the shoulders of giants like MPDF, some parts of Laravel and also the League Commonmark library.

Aaron Saray is the primary author and maintainer.

Releases

No releases published

Packages

No packages published

Languages

  • PHP 99.8%
  • HTML 0.2%