Grails renderPdf with pssword protection

懵懂的女人 提交于 2019-12-11 05:01:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!