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)