Wkhtmltopdf Plugin
Dependency :
compile ":wkhtmltopdf:0.1.7"Custom repositories :
mavenRepo "http://download.java.net/maven/2/"
Summary
Provides a Wrapper for wkhtmltopdf, a Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.
Installation
grails install-plugin wkhtmltopdf
Description
Grails Wkhtmltox / Wkhtmltopdf
This plugin provides an easy integration of the wkthmltox library into Grails.Wkhtmltopdf
"Simple shell utility to convert html to pdf using the webkit rendering engine, and qt." http://code.google.com/p/wkhtmltopdf/ GNU Lesser GPLInstallation
mac brew install wkhtmltopdflinux apt-get install wkhtmltopdfsee: http://code.google.com/p/wkhtmltopdf/wiki/compilationConfiguration
put the following line into your Config.groovy and adjust the path to your wkhtmltox binary ( which wkhtmltopdf ) grails.plugin.wkhtmltox.binary = "/usr/bin/wkhtmltopdf"Usage
to stream the content of an controller-action as pdf just call: /context/some/someAction.pdfclass SomerController {
def someAction = {
def someInstance = SomeDomainObject.get(params.id) render( filename:"File ${someInstance.id}.pdf",
view:"/some/someGspTemplate",
model:[someInstance:someInstance],
header:"/pdf/someHeader",
footer:"/pdf/someFooter",
marginLeft:20,
marginTop:35,
marginBottom:20,
marginRight:20,
headerSpacing:10,
)
}
}class SomeService implements Serializable { def byte[] pdfData = wkhtmltoxService.makePdf( view: "/pdf/someGspTemplate", model: [someInstance: someInstance], header: "/pdf/someHeader", footer: "/pdf/someFooter", marginLeft: 20, marginTop: 35, marginBottom: 20, marginRight: 20, headerSpacing: 10, ) // DO Something e.g. send as mail //sendAsynchronousMail { // multipart true // to "mail@mail.de" // subject "see PDF Attachment"; // attachBytes "PDF Attachment.pdf", "application/x-pdf", pdfData // body "see my pdf attachment" //} } }
<link rel="stylesheet" href="${resource(dir: '/css/style.css', absolute: true)}" type="text/css"/> <img src="${resource(dir: '/images/image.jpg', absolute: true)}" width="200px"/>
Options
see the following command for all options available: wkhtmltopdf --extended-helpKnown issues
- wkhtmltox must work ( try: ```wkhtmltopdf www.myhomepage.com myhomepage.pdf``` see: http://code.google.com/p/wkhtmltopdf/wiki/Usage )
- not tested on Windows