rlovtangen / grails-wkhtmltopdf Goto Github PK
View Code? Open in Web Editor NEWThis project forked from quorak/grails-wkhtmltopdf
This project forked from quorak/grails-wkhtmltopdf
I'm using version 2.5.1 from grails and add dependence in BuildConfig.groovy am getting the following error:
There was an error loading the BuildConfig: Bad artifact coordinates
wkhtmltopdf:0.1.10, expected format is :[:[:]]: (
my BuildConfig.groovy
dependencies {
...
compile 'wkhtmltopdf:0.1.10'
}
some help ?
thank you !
Sometimes I get an exception with message "getOutputStream() has already been called".
ERROR org.grails.web.errors.GrailsExceptionResolver - IOException occurred when processing request: [GET] /foo/index.pdf
Broken pipe. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_31]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Caused by: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe
at wkhtmltopdfapp.FooController.index(FooController.groovy:7) ~[main/:na]
... 3 common frames omitted
Caused by: java.io.IOException: Broken pipe
... 4 common frames omitted
ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[grailsDispatcherServlet] - Servlet.service() for servlet [grailsDispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at java.io.FilterWriter.flush(FilterWriter.java:100) ~[na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_31]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[grailsDispatcherServlet] - Servlet.service() for servlet grailsDispatcherServlet threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:578) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:212) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView.render(ErrorMvcAutoConfiguration.java:196) ~[spring-boot-autoconfigure-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:190) ~[cache-3.0.1.jar:na]
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) ~[cache-3.0.1.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:73) ~[grails-web-mvc-3.0.3.jar:3.0.3]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:523) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:433) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:305) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:399) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478) [tomcat-embed-core-8.0.23.jar:8.0.23]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_31]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.23.jar:8.0.23]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Controller:
def index() {
render( filename:"File hepp.pdf",
view:"/foo/index",
model:[someInstance:"bar"],
marginLeft:20,
marginTop:35,
marginBottom:20,
marginRight:20,
headerSpacing:10
)
}
view:
<html>
<head>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
Does not happen every time.
Current render method from trait WkhtmltopdfRenderer is:
void render(Map params) {
if (params.contentType?.toLowerCase() == 'application/pdf' || response.format == "pdf") {
def filename = params.remove("filename")
def data = applicationContext.wkhtmltoxService.makePdf(params)
response.setHeader("Content-disposition", "attachment; filename=${filename}")
response.contentType = "application/pdf"
response.outputStream.write(data)
response.characterEncoding = 'UTF-8'
response.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate') //HTTP/1.1
response.setHeader('Pragma', 'no-cache') // HTTP/1.0
response.outputStream.flush()
} else {
// Defer to original render method
super.render(params)
}
}
The pdf rendering part is more or less untouched from the original Grails 2 version of the plugin.
Hi,
I have a gsp which the image is rendered from another controller, and the image will not be displayed.
Please help, thanks.
Hi,
Grails 3.0.9
compile "org.grails.plugins:wkhtmltopdf:1.0.0.RC3"
application.yml already has pdf: application/pdf
command line works %> wkhtmltopdf www.google.com myhomepage.pdf
I am trying to generate PDF in controller/action. But it renders the the template rather than generate PDF. If i comment out render() from action it will generate empty PDF.
render( filename:"File bla.pdf",
view:"/salesRep/pdfGenerator",
model:[bla:bla],
header:"",
footer:"",
marginLeft:20,
marginTop:35,
marginBottom:20,
marginRight:20,
headerSpacing:10)
The plugin will replace the render method if contentType is "application/pdf". I can see how that is useful but how can it be disabled? I already have existing pdfs that need to be served, no need to regenerate them using this plugin.
In Grails 2.x the plugin replaced the original render method on controllers. (see WkhtmltopdfGrailsPlugin.replaceRenderMethod)
This didn't work in Grails 3 due to render method being added by trait (grails.artefact.controller.support.ResponseRenderer)
May be a bug in Groovy, Jeff Scott Brown was surprised by this behavior and opened https://issues.apache.org/jira/browse/GROOVY-7500
Hi!
I would really appreciate a working demonstration repo which would showcase the gsp templating and css at the very least. Ideally the demo would work with git clone
, ./gradlew bootRun
and navigating to http://localhost:8080/example/foo.pdf
.
I'm struggling with getting the plugin to work and cannot figure out whether the problems are in my gsp's or perhaps in the incompatible version of wkhtmltopdf binary.
Thanks.
Data type of printMediaType
should be boolean
instead of String
which is generating arguments as:
[/usr/local/bin/wkhtmltopdf, --dpi, 260, --print-media-type, true, --page-size, A5, --zoom, 1.8, --encoding, UTF-8, --title, INV-00002, -q, -, -]
But --print-media-type
flag does not accept any value and hence causing --page-size specified in incorrect location
.
Hi,
We are upgrading our App from Grails 2.5.4 to Grails 3.3.10, in the process we upgraded the version of the plugin from org.grails.plugins:wkhtmltopdf:0.1.11 to org.grails.plugins:wkhtmltopdf:1.0.0.RC9. The Font Awesome icons were rendering just fine in the earlier version of Grails, but not since the upgrade.
Here's a snippet from the CSS file that loads these fonts. any help is appreciated:
@font-face {
font-family: 'FontAwesome';
src: url('../fonts/fontawesome-webfont.eot?v=4.3.0');
src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.3.0') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff2?v=4.3.0') format('woff2'), url('../fonts/fontawesome-webfont.woff?v=4.3.0') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.3.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.3.0#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal;
}
PDF rendering is failing when the GSP contains a g:select tag. I'm able to use other grails tags along with my own tags. I am using grails 2.4.4 (also tried 2.4.5) and version 0.1.10 of the plugin. Looks like it may be an issue with the mail plugin that's doing the rendering.
Here is the error I see:
Cannot invoke method getBean() on null object. Stacktrace follows:
java.lang.NullPointerException: Cannot invoke method getBean() on null object
at show_gsp$_run_closure2.doCall(show_gsp:53)
at show_gsp.run(show_gsp:64)
at grails.plugin.mail.MailMessageContentRenderer$_render_closure1.doCall(MailMessageContentRenderer.groovy:66)
at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.with(MailMessageContentRenderer.groovy:180)
at grails.plugin.mail.MailMessageContentRenderer.render(MailMessageContentRenderer.groovy:63)
at org.wkhtmltox.WkhtmltoxService.renderMailView(WkhtmltoxService.groovy:67)
at org.wkhtmltox.WkhtmltoxService.makePdf(WkhtmltoxService.groovy:42)
at org.wkhtmltox.WkhtmltoxService.makePdf(WkhtmltoxService.groovy:37)
at MyService.generatePdf(MyService.groovy:2884)
at MyController.pdf(MyController.groovy:40)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Here's the line (913) from the grails 2.4.4 FormTagLib that I suspect the mail plugin is having issues with:
def messageSource = grailsAttributes.getApplicationContext().getBean("messageSource")
Thoughts on a work around?
I'm trying to generate pdfs with a header using the following code.
def pdf = wkhtmltoxService.makePdf(
view: "something",
header: "/pdf/header",
model: [
...
],
pageSize:"letter")
I get the following error on windows:
2015-08-12 10:28:40,318 [Thread-17] ERROR wkhtmltox.WkhtmltoxExecutor - Error: Failed loading page http://file//C:\Users\****\AppData\Local\Temp\wkhtmltopdf6840842934454361668.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
It seems to be related to wkhtmltopdf/wkhtmltopdf#1645. If wkhtmltopdf doesn't recognize the URL it will assume http... So, would it be possible not to specify "file://" prefix on windows?
The property type loop doesn't consider the type for zoom (float) so setting it won't have any affect.
I am getting some exceptions (java.lang.IllegalArgumentException) which I am not able to figure out. So basically I was following the steps mentioned in your documentation and when I call the action, I get the following exception (below ********)
The wkhtmltopdf has been installed and it is working when using from commandline.
Error 2016-01-04 16:14:58,707 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver - IllegalArgumentException occurred when processing request: [GET] /packageName/my/downloadPDFTest/1234.pdf
Could not locate mail body /my/showDetails. Is it in a plugin? If so you must pass the plugin name in the [plugin] variable. Stacktrace follows:
Message: Could not locate mail body /my/showDetails. Is it in a plugin? If so you must pass the plugin name in the [plugin] variable
Line | Method
->> 101 | createTemplate in grails.plugin.mail.MailMessageContentRenderer
| 64 | doCall in grails.plugin.mail.MailMessageContentRenderer$_render_closure1
| 180 | with . . . . . . . . in grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment
| 63 | render in grails.plugin.mail.MailMessageContentRenderer
| 67 | renderMailView . . . in org.wkhtmltox.WkhtmltoxService
| 42 | makePdf in ''
| 37 | makePdf . . . . . . in ''
| 42 | doCall in WkhtmltopdfGrailsPlugin$_replaceRenderMethod_closure3
| 162 | $tt__downloadPDFTest in packageName.MyController
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Viewport option is pretty essential for rendering pages correctly. Can we have this added in the wrapper? :) thanks!
In grails-app/services/org/grails/plugins/wkhtmltopdf/WkhtmltoxService.groovy, the line 58:
String binaryFilePath = wkhtmltopdfConfig.binary.toString()
produces the following deprecated warning:
WARN org.grails.config.NavigableMap - Accessing config key 'binary' through dot notation is deprecated, and it will be removed in a future release. Use 'config.getProperty(key, targetClass)' instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.