【问题标题】:How can you generate PDF From GSP Page in Grails?如何从 Grails 中的 GSP 页面生成 PDF?
【发布时间】:2021-10-04 09:57:10
【问题描述】:

我想将我的 gsp 页面上的信息导出为 pdf。

我该怎么做。你能分享一些例子吗。 请检查所附图片。

【问题讨论】:

  • 关于该主题还有很多其他答案;你能提供更多关于他们为什么不为你工作的信息吗?示例:stackoverflow.com/questions/29156614/…
  • @Daniel 我需要深入的解释,这里的答案只是一个概述,绿色勾号答案上共享的链接不会引导我到任何地方解释。

标签: grails


【解决方案1】:

我使用 Grails Rendering 插件从 Grails 生成 PDF。易于使用并从 GSP 生成在幕后使用 iText。

https://plugins.grails.org/plugin/grails/rendering

以下是它的调用方式,模板以下划线开头:

response.setHeader('Content-Disposition', 'inline; filename="Case_Summary_'+selectedCase+'.pdf"')

renderPdf(template: "print", model: [selectedCase: selectedCase, locationList: locationList])

这是带有一些 iText 设置的 GSP 顶部:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Case ${selectedCase} Summary</title>
    <style  type="text/css">
    @page {
        size: 8.5in 11in;
        margin: 0.25in;
        counter-increment: page;
        @bottom-right { content: "Created <g:formatDate format='MM/dd/yyyy hh:mm a' date="${new Date()}"/>"};
        @bottom-left { content: "Page " counter(page);};
    }
    body {
        font-family: 'Arial', 'sans-serif';
        font-size: 9pt;
    }
    </style>
</head>

【讨论】:

    【解决方案2】:

    也许您可以使用Grails Jasper Plugin 并创建一个与您的 GSP 格式相同的 jasper 报告,然后将其导出为 PDF。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 2013-12-11
      • 1970-01-01
      • 2020-12-15
      相关资源
      最近更新 更多