Pdf Plugin

Last updated by menilub 2 years ago

PDF plugin

Pdf plugin allows your Grails application to generate PDFs and send them to the browser by converting existing pages in your application to PDF on the fly. The underlying system uses the xhtmlrenderer component from java.net to do the rendering.

Authors : Glen Smith, Aaron Eischeid

Index

  • Releases
  • Usage
  • Tag Documentation
  • Issues

Releases




Version 0.1 - Nov-2008

Glen did all the initial work to get the essential functionality and initial documentation

Version 0.2 - 14-Feb-2009

First release to Grails repositories!

Aaron did some reworking of the tagLibraries and controllers and also improved on the documentation. The most significant addition was the ability to use simple forms.

Version 0.3 - 20-Feb-2009

new features:

  • graceful failing - if PDF generation fails for some reason you get the HTML view instead of an error page.
  • pdfLink accepts class attribute for custom styling
  • improved examples and docs
Version 0.3.1 - Mar-2009??
-compatibility with grails 1.1 (maybe already is… just not tested)

Version 0.4+ - ??
features being worked on for future releases:

  • appending existing pdf files to the pdf that is generated
  • use of post method on pdfForms
  • ability to use on secured applications

Usage




Also See the demo.gsp included with the plugin

install

grails install-plugin pdf

start up your app and go to the pdfController. You should see the demo.gsp which should give you some working examples. That simple!

designing your PDF
Design the GSP just like normal. Separate style sheets for media="print" and media="screen" are a good idea. You can use the CSS 3 @page to define page layout and margins.

@page {
    size: 8.5in 11in;  /* width height */
    margin: 0.25in;
}

The xhtmlRenderer user guide has some additional info about how to use CSS to control PDF layout.

hint: support for form elements isn't really there. Some elements (ie. checkboxes) will cause the PDF creation to fail.

Tag Documentation




g:pdfLink
attributes:

  • url (required) - the url of the gsp to want to convert to PDF
  • filename (optional) - what you want the filename of the resultant PDF to be - defualt = 'document.pdf'
  • icon (optional) - will add and <img … /> tag
  • class (optional) - set the class of element - default = 'pdf'
g:pdfForm
attributes:
  • url (required) - the url of the gsp to want to convert to PDF
  • filename (optional) - what you want the filename of the resultant PDF to be
  • name (optional) - becomes the name and id of HTML form - default = 'simplePdfForm'
  • method (optional) - the method of the form - default = 'get' (post doesn't work yet.)

Issues




  • pdfForm uses get method which is very limited.
  • in generating the pdf the controller does not have access to session or flash data. This poses serious problems if you are using security.
with jsecurity plugin you can unlock just the specific controllers and actions you need fairly easily in the SecurityFilters.groovy:
auth(controller: "*", action: "*") {
            before = {
                // Exclude the "public" controller.
                // if (controllerName == "public") return true
                if(controllerName == 'pdf') return true
                if(actionName == '[yourAction]') return true
                // This just means that the user must be authenticated. He does 
                // not need any particular role or permission. 
                accessControl { true } 
            }
        }
problems with install of 0.4 - please refer to solution
  • not tested in grails 1.1
Please log additional issues on JIRA or use the grails mailing list.