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 & HelpSyntax Questions › Save PDF output on server
Page Index Toggle Pages: 1
Save PDF output on server (Read 1597 times)
Save PDF output on server
Jul 17th, 2006, 5:42pm
 
Hello,

i've discovered the PDF export library, and i'd like save my pdf on the server.
is pdf library available in applet ?
i've read some stuff on how save images on server but nothing about vectorial files.
i need for a project to save vectorial format (eps, ai, pdf...). perhaps a vectorial library export can do the trick ?

any help, link or suggestion appreciated.

thanks !
Re: Save PDF output on server
Reply #1 - Jul 19th, 2006, 10:00am
 
Try it and see. If you've looked at how it's done for bitmap images and got that running then apply the same logic to .pdf and see what happens.

Smiley
Re: Save PDF output on server
Reply #2 - Aug 9th, 2006, 12:02am
 
yes Mark, we have investigated a little bit more.
so using the script from Seltar on processinghacks

http://www.processinghacks.com/hacks/savetoweb

we have created a php file to save data from PDF rendering on the web server.
everything is fine when the applet is running on local machine ,the php is called from the server and the pdf file is saved correctly on the server.

but when the applet is online the pdf file is not created.

the java console says :

Error while running applet.

java.lang.RuntimeException: Applet not inited properly, the sketch path could not be determined.
at processing.core.PApplet.createGraphics(PApplet.java:1032)
at processing.core.PApplet.createGraphics(PApplet.java:941)
at processing.core.PApplet.beginRecord(PApplet.java:6190)
at sketch_060808a.setup(sketch_060808a.java:127)
at processing.core.PApplet.handleDisplay(PApplet.java:1269)
at processing.core.PGraphics.requestDisplay(PGraphics.java:535)
at processing.core.PApplet.run(PApplet.java:1152)
at java.lang.Thread.run(Unknown Source)

i'm not sure to use the pdf library correctly in the applet.

any ideas ?
Re: Save PDF output on server
Reply #3 - Aug 9th, 2006, 7:24am
 
http://processing.unlekker.net/SimplePostscript/index.html

use this instead. that allows you a bit more to play with.
Re: Save PDF output on server
Reply #4 - Aug 9th, 2006, 12:35pm
 
thanks Seltar, i've tried with SimplePostscript but not better.
the SimplePostscript not seems to work in applet even on local machine (the pdf library version works fine in applet on local but not on server).

for SimplePostscript version, java console says :

Error while running applet.
java.lang.RuntimeException: Applet not inited properly, the sketch path could not be determined.
at processing.core.PApplet.sketchPath(PApplet.java:4017)
at processing.core.PApplet.savePath(PApplet.java:4034)
at SimplePostscript.SimplePostscript.open(SimplePostscript.java:53)
at simpleps.draw(simpleps.java:12)
at processing.core.PApplet.handleDisplay(PApplet.java:1336)
at processing.core.PGraphics.requestDisplay(PGraphics.java:535)
at processing.core.PApplet.run(PApplet.java:1152)
at java.lang.Thread.run(Unknown Source)
Re: Save PDF output on server
Reply #5 - Aug 9th, 2006, 2:09pm
 
The error messages that you get for SimplePostscript and PDF are basically identical, which should tell you that the problem is in processing.core.PApplet.sketchPath():

Code:
  public String sketchPath(String where) {
if (sketchPath == null) {
throw new RuntimeException("Applet not inited properly, " +
"the sketch path could not be determined.");
}
// isAbsolute() could throw an access exception, but so will writing
// to the local disk using the sketch path, so this is safe here.
if (new File(where).isAbsolute()) return where;

return sketchPath + File.separator + where;
}


The variable (not the function) sketchPath is usually set by Processing, but will fail for an applet. If you manually set the sketchPath variable to something other than null this function will not give an exception. You can try sketchPath="."; or sketchPath="/name/of/your/applet/directory/" (insert real name).

But this still won't work for an applet running in a browser, since writing files is a violation of security. Hence you need a way to get around it, such as by using a PHP script to write the data to the server. There is code elsewhere on this board that should give you a hint of how to do this.
Re: Save PDF output on server
Reply #6 - Aug 9th, 2006, 3:33pm
 
the point is that if the security situation prevents you from reading/writing files, then sketchPath() will neither work, nor will it be useful to you. if the applet is signed, then sketchPath should work fine.
Re: Save PDF output on server
Reply #7 - Aug 9th, 2006, 3:46pm
 
Thanks a lot Marius for this clear explanation.
You are right, there is still the problem of security restriction to write a file when the applet is running in a browser.
So, a solution could be not using the created file by SimplePostscript BUT grab the data before write it in the file and send this by post protocol to the php file.
Do you think it's possible ?
Do you know a way to bufferise the data in a variable instead  of write a file ?

It could be interested to have possibility to assign in a variable the result of any exporting library to made the data available by server scripts. This way the security restriction could be managed to execute export stuff on online application.
do you think this make sense ?

thanks again for your help.
Re: Save PDF output on server
Reply #8 - Aug 10th, 2006, 7:25am
 
I've done this on lots of my applets! Check out Flowerpower.
http://seltar.org
That saves the screen as a simple-postscript to memory (instead of disc.. rewrote it to suit my needs), then dumps it all in a post to php as a file, so i can just run move_uploaded_file() in php.

I also do this for most of my save-image functions.


best
seltar
Re: Save PDF output on server
Reply #9 - Aug 11th, 2006, 12:54am
 
Seltar, your site is awesome.
your save function is exactly what i want.
i will look your code in detail and learn a lot...

a big thank for sharing this.
Re: Save PDF output on server
Reply #10 - Apr 8th, 2010, 11:29am
 
I wonder if you have an applet online and you want to save a pdf to the user's desktop is that process similar?

Do you just need to get your applet signed and specify the SketchPath?
Page Index Toggle Pages: 1