We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › pdf saving user friendliness
Page Index Toggle Pages: 1
pdf saving user friendliness (Read 994 times)
pdf saving user friendliness
Jul 21st, 2007, 2:34pm
 
Hi

I'm making an end-user application which generates pdfs based on user input. Depending on the complexity of the input the pdf files can take a really long time to save, and the application gets stuck during that time.

I was wondering if there is a way to make this more user friendly. 2 specific questions (based on Java inexperience, I'm afraid)

- Can I make the pdf saving on a thread? and if so, where could I find good references for doing that (I think simple thread usage in processing could do).

- Is there a way to add a progress bar to the process? I don't really need components or so. I would be fine if I find a way to retrieve the savedBytes during the process.

Any pointers greatly appreciated.

Thanks a lot
Re: pdf saving user friendliness
Reply #1 - Jul 21st, 2007, 2:48pm
 
a pdf can be saved on a thread when it's done with createGraphics().

the progress bar wouldn't really be possible because most of the time is spent inside itext, which is just a bit pokey. in 0125, i've upped the buffer size for the files being written by pdf, but that will only improve the raw speed of writing the file to disk, not the computation for it.

to do it on a thread, check out the java thread tutorial. basically, you just subclass Thread, put the block of code that you want threaded inside a run() method, and call start(). *note that it cannot be used to make calls to the main drawing surface* because you're not guaranteed that the thread will be running when draw() is active.

good luck!
Re: pdf saving user friendliness
Reply #2 - Jul 21st, 2007, 6:42pm
 
mm, from your response I infer (and now it looks obvious) that most of the time is spent computating the pdf rather than saving it to disk... I guess I'll have to put that process (createGraphics rather than save) on a thread. correct me if I'm wrong.

I'll check the tutorial. It looks less scary with your tips Smiley

thanks a lot

Re: pdf saving user friendliness
Reply #3 - Jul 21st, 2007, 9:18pm
 
wow I hadn't tested my code with 0125. It is far faster without any changes!!

for a quick test: the same ~600 kb pdf takes to be generated/saved

p-0124 - 1 min
p-0125 - 15 secs

Can I access the buffer size to play with other values? I've checked PGraphicsPDF in the javadoc but haven't found anything useful.

anyway, this is absolutely great. thanks a lot for the improvements (and everything else)

best!
Re: pdf saving user friendliness
Reply #4 - Jul 21st, 2007, 9:47pm
 
there's no way to change it without recompiling, the buffer is set to 16384 (16kb) inside beginDraw() if you wanna futz with it. for an 600k file i'm guessing 16k will be a decent buffer size, but you're obviously welcome to mess with it a bit. you could probably even just make a new tab, and do:

Code:

import processing.pdf.*;

public class BigPDF extends PGraphicsPDF {
public void beginDraw() {
// contents of beginDraw() with your changes goes here
}
}


and then in your main code:

size(800, 800, "BigPDF");

and see if that lets you change it without recompiling pdf.jar.
Re: pdf saving user friendliness
Reply #5 - Jul 21st, 2007, 11:12pm
 
I'll try that. If it doesn't work it can be a good opportunity for trying to compile processing myself :)

thanks a lot, ben.
Page Index Toggle Pages: 1