问题
Does anyone know how to apply a password on renderPdf (org.grails.plugins:rendering:2.0.3) on Grails 3.0.8? I have tried googled but not result.
回答1:
In order to password-protect your PDF-files you have to use the lower level stuff, like:
import org.xhtmlrenderer.pdf.*
void renderEncPdf( String url, out ){
def enc = new PDFEncryption( 'userPassword'.bytes, 'ownerPassword'.bytes )
ITextRenderer renderer
try{
renderer = new ITextRenderer()
renderer.setPDFEncryption enc
renderer.setDocument url
renderer.layout()
renderer.createPDF out
}catch( Throwable e ){
log.error e
}finally{
renderer.finishPDF()
}
}
the url
should be the absolute url of your GSP-view you use for generation.
For this I didn't use any plugin (as the documentation is missing now), it's a simple itext
dependency. It should be also possible to hook in with rendering
plugin somehow
来源:https://stackoverflow.com/questions/38971634/grails-renderpdf-with-pssword-protection