具有pssword保护的Grails renderPdf [英] Grails renderPdf with pssword protection
问题描述
有人知道如何在Grails 3.0.8的 renderPdf (org.grails.plugins:rendering:2.0.3)上应用密码吗?我尝试用google搜索,但没有结果.
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.
推荐答案
要用密码保护您的PDF文件,您必须使用较低级别的内容,例如:
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()
}
}
url
应该是用于生成的GSP视图的绝对URL.
the url
should be the absolute url of your GSP-view you use for generation.
为此,我没有使用任何插件(因为现在缺少文档),它是一个简单的itext
依赖项.还应该可以以某种方式使用rendering
插件
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
这篇关于具有pssword保护的Grails renderPdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!