我想将视图渲染为pdf,并尝试使用Grails渲染插件2.0.3
我尝试了最简单的gsp-file开始:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample title</title>
</head>
<body>
<h1>Sample line</h1>
</body>
</html>
在控制器中:
def report() {
def OfferHeader oh = OfferHeader.get(15)
println(">>> Offerheader: "+oh.sawMill)
// render(template: "/offerHeader/Test")
renderPdf(template: "/offerHeader/Test", filename: "offertrapport.pdf")
}
最后是:
2017-04-14 11:26:55.989 ERROR --- [nio-8080-exec-6] o.g.web.errors.GrailsExceptionResolver : NullPointerException occurred when processing request: [GET] /offerHeader/report/15
Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:210)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
at grails.plugin.springsecurity.web.UpdateRequestContextHolderExceptionTranslationFilter.doFilter(UpdateRequestContextHolderExceptionTranslationFilter.groovy:64)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:158)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1337)
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1197)
at java.beans.Introspector.getBeanInfo(Introspector.java:426)
at java.beans.Introspector.getBeanInfo(Introspector.java:173)
at grails.plugins.rendering.document.RenderEnvironment.init(RenderEnvironment.groovy:31)
at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:68)
at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:60)
at grails.plugins.rendering.document.XhtmlDocumentService.generateXhtml(XhtmlDocumentService.groovy:65)
at grails.plugins.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:35)
at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:36)
at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:35)
at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:65)
at grails.plugins.rendering.RenderingTrait$Trait$Helper.render(RenderingTrait.groovy:66)
at grails.plugins.rendering.RenderingTrait$Trait$Helper.renderPdf(RenderingTrait.groovy:45)
at com.torntrading.portal.OfferHeaderController.$tt__report(OfferHeaderController.groovy:123)
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:96)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93)
... 37 common frames omitted
我错过了什么?或者它不应该与这个版本的grails(3.2.4)一起使用?
也许有更好的插件可以使用?
出于某种原因,您需要在构建中添加依赖项。gradle使其工作:
runtime "org.springframework:spring-test:4.2.1.RELEASE"
首先将以下依赖项添加到build.gradle:
dependencies {
...
runtime "org.springframework:spring-test:4.2.1.RELEASE"
}
然后,假设我们将在gsp中点击一个链接来呈现pdf:
<g:link action="report" params='[offerId: "${offer.id}"]'>To PDF</g:link>
然后在控制器中:
def report() {
def offer = Offer.get( params.offerId )
renderPdf(template: "offerpdf", model: [offer: offer], filename: "offer.pdf")
}
在您的offer views目录中,您将有一个名为offerpdf的模板gsp。普惠制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Offer</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Offer: ${offer.id}</h1>
</body>
</html>
我刚刚安装了grails渲染插件,并想使用它来生成PDF文件。我创建了简单的模板,但此插件不渲染检查输入元素。当我将输入写为以下内容时: 我收到以下错误消息: 当我添加结束标记时,如下所示: 我在PDF中没有任何检查元素。我不是说,我想要在交互模式下进行检查,但是,我想要一个看起来像复选框的图像
问题内容: 我刚刚安装了grails渲染插件,并希望将其用于生成PDF文件。我已经创建了简单的模板,但是没有任何CSS样式即可将其导出。如果仅从grails渲染模板,则页面将在Web浏览器中显示所有样式。 所以,我的问题是-在PDF生成过程中如何正确包含CSS文件? 我的模板: 而且我的webui.css中具有样式.odd,但是它不适用于该行。 任何帮助,将不胜感激。 Edit1:我发现以以下方式
我正在尝试使用渲染插件将一个简单的模板保存到pdf,但无论我怎么尝试都无法让它工作。我所需要的只是让它在服务器上的文件系统中保存一个文件并重定向到不同的页面。 此时,pdf模板不需要任何参数,因为它只打印hello world。一旦我开始工作,我会尝试添加一些数据。 我收到错误消息,说如果没有附加“/”,我需要指定控制器。但我试图添加这一点,但没有任何效果。另外,我不知道它需要哪个控制器,因为我已
我想在PDF文档中嵌入HelveticaNeueLTCom-BdCn.ttf。我正在使用Grails渲染0.4.4插件生成PDF文件。我尝试遵循, 但它不起作用。
问题内容: 我有一个JSF表单,上面有一个selectBooleanCheckbox。如果该复选框的值为true,则要在其旁边显示组合框。但是不知何故它不起作用。 这是我的代码: Bean类方法: 注意:从FireBug复制 这是POST请求: 响应: 问题答案: 实际上,实现所需功能的直接方法是根据复选框的选择重新呈现组合框。这可以通过以下方式完成: 请注意,该代码在Bean中不需要任何特殊字段
问题内容: 今天遇到了这个奇怪的结果,试图在Grails 2.0.4中将对象列表呈现为JSON …(我知道我会后悔由于我鼻子底下的东西而问这个问题…… 已更新 5/26,我的预测是正确的,请参见下文:-)) 这很好用;JSON在浏览器中正确呈现… ..so为什么缩短的版本没有工作? 上面代码生成的JSON作为单行文本输出,因此我怀疑它没有被拾取,但是正确地加上了括号,这是怎么回事? [‘produ