PHPackages                             maxchene/kirby-pdf - 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. maxchene/kirby-pdf

ActiveKirby-plugin[PDF &amp; Document Generation](/categories/documents)

maxchene/kirby-pdf
==================

Kirby plugin that a PDF engine to convert HTML to PDF

1.0.2(2y ago)2317[2 issues](https://github.com/maxchene/kirby-pdf/issues)MITPHPPHP &gt;=8.1

Since Aug 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/maxchene/kirby-pdf)[ Packagist](https://packagist.org/packages/maxchene/kirby-pdf)[ Docs](https://github.com/maxchene/kirby-pdf)[ RSS](/packages/maxchene-kirby-pdf/feed)WikiDiscussions main Synced 1mo ago

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

Kirby PDF
=========

[](#kirby-pdf)

This plugin allow you to choose a PDF engine to render HTML as PDF.

WIP
---

[](#wip)

For now this plugin is only working with [WkHtmlToPdf](https://wkhtmltopdf.org/) installed on your server.

More engines will be coming soon: tcpdf, dompdf, mpdf.

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

[](#installation)

Download and copy this repository into `site/plugins/pdf`

Or use composer : `composer require maxchene/kirby-pdf`

Rendering
---------

[](#rendering)

### Rendering with current template

[](#rendering-with-current-template)

This is the simplest render. PDF engine will parse the current page with her current template and css to render the PDF file.

For this rendering, you might want to use [print media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/@media)and [page media query](https://developer.mozilla.org/fr/docs/Web/CSS/@page) to fit your needs.

### Dedicated pdf template

[](#dedicated-pdf-template)

Sometimes rendering a pdf with media queries can be tricky, and sometimes you'll want a different rendering between HTML page and PDF file for the same data.

In this case, you can configure a dedicated template for the PDF rendering using a custom css file and custom HTML tree.

To activate dedicated template, you have to create a new template with the same name as your page template in the `pdf`subdirectory of your `templates` folder.

This is an example with a `recipe` page template :

```
├── snippets
├── templates
│   ├── pdf
│   │   ├── recipe.php    [
    'margin' => [
        'bottom' => 10,         // margins unit is millimeter(mm)
        'left' => 10,
        'right' => 10,
        'top' => 10,
    ],
    'orientation' => 'portrait' //either 'portrait' or 'landscape'
]
```

Orientation can be either `portrait` or `landscape`, default is portrait.

Note that margins are in millimeters (mm).

How to use in your templates
----------------------------

[](#how-to-use-in-your-templates)

Here is a quick example of how you can use page to PDF in your template:

```
Guacamole recipe
