PDF Rendering to a file on the server.

735 views
Skip to first unread message

Mark Ellul

unread,
Mar 22, 2011, 2:41:07 PM3/22/11
to play-fr...@googlegroups.com
Hi,

I have a app that renders 1 template to PDF, the first render takes a while. When in Development mode its not issue, but in Production (I am using Amazons Elastic Beanstalk) I get timeouts.

I am in the process of upgrading my project to Play 1.1.1 with the new PDF 0.2 module which seems to have resolve most of the issues but it still could be better.

So what I am thinking...

Today I wrote an asynchronous scheduled job which runs 2 seconds after startup (started with a boot to start a render though not using the controller I tried to write to a temp file.

Heres the code

try {
Options options = new Options();
options.pageSize = IHtmlToPdfTransformer.A4P;
File test = utils.helpers.S3Helpers.createTempFile("test.pdf");
Template t = play.templates.TemplateLoader.load("misc/startup_pdf.html");
writePDF(test,t, options, new HashMap<String, Object>());
} catch(Exception e) {
e.printStackTrace();
}

and I have tried this as well

try {
Options options = new Options();
options.pageSize = IHtmlToPdfTransformer.A4P;
File test = utils.helpers.S3Helpers.createTempFile("test.pdf");
Template t = play.templates.TemplateLoader.load("misc/startup_pdf.html");
try {
    OutputStream os = new FileOutputStream(test);
    PDFDocument singleDoc = new PDFDocument();
    MultiPDFDocuments docs = new MultiPDFDocuments();
        docs.add(singleDoc);
    renderTemplateAsPDF(os, docs );
    os.flush();
os.close();
} catch (IOException e) {
throw new Exception(e);
}

Which throws an exception below... The Exception occurs because its trying to get

I was wondering if anyone has managed to create a PDF not in a Request's Controller? I,e writing the file to the server in a job.

That is what is causing the NullPointerException.

Any Pointers?
 

Path[ QS: C:]java.lang.NullPointerException
at play.modules.pdf.PDF.writePDF(PDF.java:136)
at play.modules.pdf.PDF.writePDF(PDF.java:121)
at tasks.AsyncBootStrapPDFGenerate.doJob(AsyncBootStrapPDFGenerate.java:22)
at play.jobs.Job.doJobWithResult(Job.java:37)
at play.jobs.Job.call(Job.java:110)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

chasd00

unread,
Mar 22, 2011, 10:59:29 PM3/22/11
to play-framework
I don't know about the job but you may try updating the pdf module.
IIRC a while back the author posted that the long time to generate the
first pdf was because of some kind of timeout or something. I believe
it has since been fixed.

chasd00

unread,
Mar 22, 2011, 11:05:29 PM3/22/11
to play-framework

Mark Ellul

unread,
Mar 23, 2011, 6:00:57 AM3/23/11
to play-fr...@googlegroups.com, chasd00
Hi Chasd00,

I did that and the render time has increased markedly. However I was looking to speed it up to be really fast. It says that the stylesheet I am using now takes 150ms to parse, however it really takes alot longer to do the first render around 10 to 15 seconds, after the first render its almost instant.

Has anyone else done something similar?

I also need to do a render and send the outputted pdf into a email.

Would I still need to do that in a Http Request?

Thanks in advance


Nicolas Leroux

unread,
Mar 23, 2011, 6:08:26 AM3/23/11
to play-fr...@googlegroups.com
Hi,

It might really be well another bug, could you report this issue on

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

Thanks,

Nicolas

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Morten Kjetland

unread,
Mar 23, 2011, 6:33:59 AM3/23/11
to play-fr...@googlegroups.com
It crashed when it tries to use the current request-object which does not exists in Jobs in Play 1.1.1.

This was fixed in master a few days ago:


-Morten

Mark Ellul

unread,
Apr 5, 2011, 6:40:46 AM4/5/11
to play-fr...@googlegroups.com
Thanks Morten and Nicolas, you input is appreciated.

Morten, I cannot figure out if this fix is in the play 1.1.1 branch or master? Do you know?


Morten Kjetland

unread,
Apr 5, 2011, 6:47:59 AM4/5/11
to play-fr...@googlegroups.com
This is the ticket:

Is is fixed in 1.2 so you find it in the current release candidate and in master.

-morten

On Tue, Apr 5, 2011 at 12:40 PM, Mark Ellul <mark....@gmail.com> wrote:
Thanks Morten and Nicolas, you input is appreciated.

Morten, I cannot figure out if this fix is in the play 1.1.1 branch or master? Do you know?


Reply all
Reply to author
Forward
0 new messages