Pdf Plugin
Dependency :
compile ":pdf:0.6"
Summary
Installation
grails install-plugin pdf
Description
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.
Version 0.1 - Nov-2008
Glen did all the initial work to get the essential functionality and initial documentationVersion 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:
(currently available on github) -- http://github.com/aeischeid/grails-pdfplugin
(source on gitHub, but can install from grails SVN repo again)
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.The xhtmlRenderer user guide has some additional info about how to use CSS to control PDF layout.
g:pdfLink
attributes:
attributes:
Take a look at the Rendering Plugin for similar functionality.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 documentationVersion 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
- 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 (http://github.com/aeischeid/grails-pdfplugin)
- most form elements now simply get ignored instead of throwing errors
(currently available on github) -- http://github.com/aeischeid/grails-pdfplugin
- 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.
(source on gitHub, but can install from grails SVN repo again)
- fix brokenness caused by change in way grails render and include tagLibs worked.
- CSS still needs absolute URLs for images, but gsp can have relative
- pdfLink tag can now go through controller and action as well, (couldn't get templates working yet.)
- fix install script for demo files
- added a few new files that plugins need
- mild attempt to update demo files
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;
}XHTML form elements get ignored, but occasionally they will cause PDF generation to fail. It's best to leave them out if possibleTagLibs and pdfController are just a fast and dirty way of getting a pdf. In a production environment you probably want to bypass these and build your forms and links more precisely. It is not all that difficult. Essentially you need to pass the pdfService method either a url, or render a Dom as a string with a baseUrl. Use the included controller and demo files as examples.
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'
- pdfController (optional) - If you want to go through controller… like you would expect...
- pdfAction (optional) - like you would expect...
- pdfId (optional) - like you would expect...
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 only allows for security if using pdfController/pdfAction params
- customized xhtmlRenderer uses old iText version causing it to break with newer iText in the export plugin