PDF rendering from inside a job

180 views
Skip to first unread message

Alison Winters

unread,
Jul 14, 2011, 8:11:41 PM7/14/11
to play-framework
In this thread: http://groups.google.com/group/play-framework/browse_thread/thread/cbf2af5b20a43893
someone asked if they could render a PDF file while inside a job. It
was determined that this was not possible at the time because when
you're in a job there is no current request object. There was a fix
for sending mails in a job in 1.2 that created a fake request object,
but the implementation of that was changed in 1.2.2 so we no longer
have a fake request object. So we still get NPE:

Caused by: java.lang.NullPointerException
at play.modules.pdf.PDF.writePDF(PDF.java:159)
at play.modules.pdf.PDF.writePDF(PDF.java:144)
at controllers.Reports$1.doJobWithResult(Reports.java:316)
at controllers.Reports$1.doJobWithResult(Reports.java:1)
at play.jobs.Job.call(Job.java:146)
... 8 more

Looking at the PDF module source code, it looks like it only really
needs the request for three things:

1. to find the current template name when none is supplied (PDF line
159),
2. to resolve the template name if it hasn't been supplied with full
dotted notation (PDF line 197/RenderPDFTemplate line 60), and
3. to pass the base URI into YaHP (RenderPDFTemplate line 116)

All of these problems could be worked around by moving around code to
allow for a null request except in precisely the point where it is
necessary. Is this a solution that might be looked at for the module,
or is there another workaround that I don't know about?

Alison

Nicolas

unread,
Jul 16, 2011, 4:28:55 PM7/16/11
to play-fr...@googlegroups.com
I thought this issue was solved. I am not sure what you are proposing will work for all use cases but we might want to add extra method for this specific use case. I seem to rememeber we add to also patch the YAHP library to use play so it might be a bit more tricky.

Alison Winters

unread,
Jul 18, 2011, 5:07:16 PM7/18/11
to play-framework
It seems the issue came back in 1.2.2 :( Or maybe it never was fixed -
I didn't use the PDF module till now. I know that my proposal
definitely won't work for all cases, but it should work for most of
them (assuming YaHP or Flying Saucer don't need the base URI to be
100% correct). I have opened a bug on Github to cover this case:

https://github.com/pepite/play--pdf/issues/18

Thanks!
Alison
Reply all
Reply to author
Forward
0 new messages