The prawnto plugin gives all controllers access to the
prawnto
method that controls the prawnto/prawn options.
This method is provided as both an instance and a class method to fascilitate complete DRYness. The class method
assignment is inherited and can be trumped by child classes just as you would expect, similar to many other rails class level features (layout, filter, etc).
And, just as you would expect, the instance method trumps anything specified by the class method.
The
prawnto
method takes an options hash as its single argument.
Prawnto options are specified at the top level, and Prawn::Document options are specified as a subhash under the :prawn key.
This is all probably better understood through examples:
Lets say you want all pages created with a particular controller to be landscape and served as attachments,
then just invoke prawnto at the controller class level with:
prawnto :prawn=>{:page_layout=>:landscape}, :inline=>false
Lets say that in that same scenario there is one action that should be served inline,
then just invoke prawnto within the action to override:
prawnto :inline=>true
Lets say that you know all pages in all controllers will have the same margin,
then just specify it in the ApplicationController class:
prawnto :prawn => {
:left_margin => 48,
:right_margin => 48,
:top_margin => 24,
:bottom_margin => 24}
Here is the complete list of recognized prawnto options
-
:prawn
the hash passed to the Prawn::Document object. All your normal prawn options are specified here.
-
:inline
controls whether the pdf gets downloaded as an attachment or whether it is viewed inline within the browser. true by default.
-
:filename
filename associated to pdf. defaults to the name given by the url.