Skip to content
A simple Rails wrapper for the PrinceXML PDF generation library.
Ruby
Pull request Compare This branch is 10 commits ahead, 77 commits behind mbleigh:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
.gitignore
MIT-LICENSE
README.rdoc
Rakefile
VERSION
princely.gemspec

README.rdoc

Princely

Princely is a simple wrapper for the Prince XML PDF generation library (www.princexml.com). The plugin will also automatically registers the PDF MimeType so that you can use pdf as a format in controller respond_to blocks.

The behaviour of this fork differs from the original version!

Rendering to a string and passing it to prince is no longer done because that broke almost all unicode stuff. Now the url for the current controller action is passed to prince. Therefore you need to keep sure that this url is accessible from the prince application.

Example

class Provider::EstimatesController < Provider::BaseController
  # You can render PDF templates simply by
  # using the :pdf option on render templates.
  def show
    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => "file_name", 
               :template => "controller/action.pdf.erb",
               :stylesheets => ["application","prince"],
               :layout => "pdf"
      end
    end
  end

  # Alternatively, you can use make_and_send_pdf to
  # render out a PDF for the action without a
  # respond_to block.
  def pdf
    make_and_send_pdf("file_name")
  end
end

Render Defaults

The defaults for the render options are as follows:

layout:      false
template:    the template for the current controller/action
stylesheets: none

Working with the Rails Asset Pipeline

From Rails 3.1, stylesheets are served through the Rails Asset Pipeline. In order for Princely to be able to find your stylesheets in development mode you must run:

rake assets:compile

which will compile them into the public/assets directory.

Unfortunately this means that you must recompile your assets each time you make a change for princely to see your latest version. Remember to remove the public/assets directory after you’re done testing your PDFs.

Contributors

  • Gemification and more: Nic Williams

Resources

  • Copyright © 2007-2009 Michael Bleigh and Intridea, Inc., released under the MIT license.

Something went wrong with that request. Please try again.