# Kirby + PrinceXML?

**URL:** <https://forum.getkirby.com/t/kirby-princexml/2393>\
**Category:** Questions\
**Tags:** v2\
**Created:** [November 3, 2015, 4:57pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393 "2015-11-03T16:57:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tart2000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tart2000/32/518_2.png) [@tart2000](https://forum.getkirby.com/u/tart2000)\
**Post date:** [November 3, 2015, 4:57pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/1 "2015-11-03T16:57:12Z")

</div>

Dear fellow Kirby lovers,

Has anyone tried to plug Kirby with [PrinceXML][1]?

What I want to do is:

- generate content through Kirby
- create a beautiful PDF (with pages etc.) from the content

Also, if some of you have other ideas on how to do that, please let me know.

Thank you  
[1]: [http://www.princexml.com/](http://www.princexml.com/)

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 3, 2015, 6:40pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/2 "2015-11-03T18:40:08Z")

</div>

You can use [the Prince PHP library](http://www.princexml.com/doc/php/) to access Prince from your PHP code.

Regarding Kirby integration: You can simply drop the `prince.php` into your plugin directory and then create another plugin that uses the library in the Kirby context. A good way of implementing dynamic PDF generation could be to create a route that serves the PDF of a given page:

```php
// Make sure to load Prince before this plugin
kirby()->plugin('prince');

kirby()->routes(array(
  array(
    'pattern' => 'pdf/(:all)', 
    'action' => function($path) {
      $page = page($path);
      $prince = new Prince('<path>');
      
      // Do stuff with $page and generate HTML code for the PDF
      // You could use an HTML template inside your plugin
    }
  )  
));

```

---

<div class="post-metadata">

**Author:** ![tart2000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tart2000/32/518_2.png) [@tart2000](https://forum.getkirby.com/u/tart2000)\
**Post date:** [November 3, 2015, 7:56pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/3 "2015-11-03T19:56:59Z")

</div>

Thanks @lukasbestle!  
This looks really exciting! Have you tried it yourself?  
Would you recommend using Prince? Or do you know of a better (cheaper) option?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 3, 2015, 8:10pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/4 "2015-11-03T20:10:58Z")

</div>

I have used Prince for a project that required dynamic HTML to PDF conversion. Prince is the only good library for this use-case.

If you only need a static template (the same layout, only different content), I can highly recommend [TCPDF](http://www.tcpdf.org). It has an awful API but once you know how to use it, it works pretty well. And it’s free and open source. 😃

If you want to use TCPDF, you can swap out the word `prince` with `tcpdf` in my previous post. It works with Kirby in the same way.

---

<div class="post-metadata">

**Author:** ![tart2000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tart2000/32/518_2.png) [@tart2000](https://forum.getkirby.com/u/tart2000)\
**Post date:** [November 3, 2015, 8:38pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/5 "2015-11-03T20:38:45Z")

</div>

Thanks @lukasbestle  
TCPDF: OMG this website…  
Would you have a place where I can see it work?  
Cheers!

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 3, 2015, 8:50pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/6 "2015-11-03T20:50:32Z")

</div>

> [@tart2000](#):
>
> OMG this website…

It gets even worse once you take a look at the documentation and the source code. 😉

> [@tart2000](#):
>
> Would you have a place where I can see it work?

I don’t have any public TCPDF examples, but you can learn a lot about how it works in the official examples.

---

<div class="post-metadata">

**Author:** ![tart2000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tart2000/32/518_2.png) [@tart2000](https://forum.getkirby.com/u/tart2000)\
**Post date:** [November 3, 2015, 8:52pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/7 "2015-11-03T20:52:01Z")

</div>

OK I’ll try and dig into it.  
Thanks a lot

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 3, 2015, 9:00pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/8 "2015-11-03T21:00:53Z")

</div>

You are welcome. 😄

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:04pm UTC](https://forum.getkirby.com/t/kirby-princexml/2393/9 "2025-02-06T17:04:16Z")

</div>

Archived on February 6, 2025, 5:04pm UTC


