Login required
Download

Pdf Plugin

(2)
Author(s): aeischeid
Current Release: 0.4
Grails Version: 1.1 > *
Tags pdf report
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!

so far I have not released latest version into grails repository (reluctant to go back to SVN...), but it is easy to get the .zip from github and install using that

update - got rough copy of latest plugin into grails repo's should be able to do grails install-plugin pdf and get 0.4 version

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 : Aaron Eischeid, Glen Smith

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.4 - 27-Apr-2009
  • update to new version of XHTMLrenderer and iText
  • ability to use post method on pdfForms (images and external CSS must have absolute URLs)
  • ability to generate pdf from either templates or to go through control action.
  • ability to use on secured applications (must use method="post").
  • project now hosted on GitHub, but rough copy in grails plugin repository
  • most form elements now simply get ignored instead of throwing errors
Version 0.4.5 - 5-May-2009
(currently available on github
  • modify XHTMLrenderer to allow images to be rendered in PDF when relative URL's are used in GSP
  • cleaning tag library code and fixing some minor bugs in tag rendering.

Usage




Also See the demo.gsp included with the plugin

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.

XHTML form elements get ignored, but occasionally they will cause PDF generation to fail. It's best to leave them out if possible

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'
  • template (optional) - template you want to render as a pdf, method must = post (since 0.4)
  • controller (optional) - requires action method='post' (since 0.4)
  • action (optional) - controller action for rendering PDF (since 0.4)

Issues




  • pdfLink still uses limited get method for sending params, and still doesn't allow for security
  • in generating the pdf the controller does not have access to session or flash data. This poses serious problems if you are using security. no longer an issue in latest release if you use method='post'
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 } 
            }
        }

Please log additional issues on GitHub project page or use the grails mailing list.