# \[ANN\] Princely - Prince XML PDF Wrapper Plugin

**URL:** <https://www.ruby-forum.com/t/ann-princely-prince-xml-pdf-wrapper-plugin/123831>\
**Category:** Rails\
**Created:** [December 21, 2007, 2:59am UTC](https://www.ruby-forum.com/t/ann-princely-prince-xml-pdf-wrapper-plugin/123831 "2007-12-21T02:59:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 21, 2007, 2:59am UTC](https://www.ruby-forum.com/t/ann-princely-prince-xml-pdf-wrapper-plugin/123831/1 "2007-12-21T02:59:55Z")

</div>

Recently I was implementing PDF generation for a project utilizing the  
fantastic library Prince XML ([http://www.princexml.com](http://www.princexml.com)). I came across  
a blog article with a basic library and helper set for Prince (http://  
[sublog.subimage.com/articles/2007/05/29/html-css-to-pdf-using-ruby-on-](http://sublog.subimage.com/articles/2007/05/29/html-css-to-pdf-using-ruby-on-)  
rails), which provided a great basis. I wanted to make something a  
little more generalized and in-keeping the Rails Way, so I have  
created ‘Princely’, a simple wrapper utilizing much of the code from  
the SubImage library but giving it better helpers and pluginizing its  
inclusion.

== Installation ==

The first step is to download Prince ([Prince - Download Prince 15.1](http://princexml.com/download/))  
and install it on your platform of choice (only Linux and Mac OS X  
supported by the plugin at this time). Next, simply install the  
plugin:

script/install plugin [http://svn.intridea.com/svn/public/princely](http://svn.intridea.com/svn/public/princely)

You are now ready to get started using Princely to generate PDF. Note  
that Princely is only compatible with Rails \>= 2.0

== Usage ==

Princely uses the MimeTypes and respond\_to blocks from Rails 2.0 to  
add PDF as a render option and a format. Because of this, it’s  
incredibly easy to implement a PDF! Simply make your XHTML or XML  
template and use pdf as the format (e.g. show.pdf.erb), then add code  
similar to this in your controller:

class PagesController \< ApplicationController  
def show  
respond\_to do |format|  
format.html  
format.pdf {  
render :pdf =\> @page.pdf\_name,  
:template =\> “show.pdf.erb”, # not required, shown for  
example  
:layout =\> false # not required  
}  
end  
end  
end

And that’s all there is to it! If you add a .pdf to your properly  
routed path, you should be presented with a PDF version of the page  
generated by Prince. The README ([http://svn.intridea.com/svn/public/](http://svn.intridea.com/svn/public/)  
princely/README) has more detailed usage information.

There is a Trac ([http://trac.intridea.com/trac/public/](http://trac.intridea.com/trac/public/)) available for  
any bugs or patches you might come across. Additionally you can  
comment on this at the original blog post ([http://www.intridea.com/](http://www.intridea.com/)  
2007/12/20/announcing-princely-rails-prince-xml-pdf-wrapper).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 9, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/ann-princely-prince-xml-pdf-wrapper-plugin/123831/2 "2008-07-09T18:38:59Z")

</div>

Just as an update for those interested, the path supplied for the plugin  
is no longer valid. Its been moved from a svn repository to git and is  
available at the following location:

> **[GitHub - mbleigh/princely: A simple Rails wrapper for the PrinceXML PDF...](https://github.com/mbleigh/princely/tree/master)**
>
> master
