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 › Make a PDF at the desktop
Page Index Toggle Pages: 1
Make a PDF at the desktop? (Read 1135 times)
Make a PDF at the desktop?
Apr 6th, 2009, 8:43pm
 
Starting from scratch (totally clueless), I would like the standalone application to print the current window. I see only the processing.pdf library as a means so I working with it. I can create the PDF but I cannot print it to the desktop without explicitly indicating the full path as /Users/<me>/Desktop/<pdf name>. The application could be running on any machine with any user. If I try something like ~/Desktop/<pdf name> I wind up with a folder ~ and a folder Desktop created with the pdf in the latter. In fact, the pdf library seems to create the path structure if it does not already exist. So, one, is there a way to print (working in OSX) and if not then how can I create the PDF at the desktop without hardcoding a specific path? Thanks.
Re: Make a PDF at the desktop?
Reply #1 - Apr 7th, 2009, 1:54am
 
Maybe Printer Output thread can help (haven't tried).
Re: Make a PDF at the desktop?
Reply #2 - Apr 8th, 2009, 5:23pm
 
Thanks for the link. I see nothing there that looks like help. I'll dig deeper. The post are a bit dated also. It branches into an old thread that is actually about the PDF library, but again I see nothing. I figured this is such a basic question and need that someone would have an answer.
Re: Make a PDF at the desktop?
Reply #3 - Apr 9th, 2009, 5:50am
 
I was referring to seltar's code, using the Java Print API, which probably haven't evolved a lot since 2006.
I started myself to look at this API, finding it interesting, but I can't help yet.

Beside, I have read more attentively your message, beyond the PDF and print keywords...  Tongue I don't think you need to output a file to print, so it might solve your problem.
I guess you are running on a Mac (ah, yes, you mention OSX), so nearly a Unix system. So you should put your temp file in /tmp, that's what it is made for (unless Macs haven't this folder?).
Or in a more Java way, you can get the official temp dir with String tmpDir = System.getProperty("java.io.tmpdir");
Re: Make a PDF at the desktop?
Reply #4 - Apr 18th, 2009, 1:03pm
 
Thanks, actually Mac OSX is a Unix system with an interface on top. So for example printing is handled by CUPS but the user would never know it. Knowing that, how would I shift the PDF written to /tmp out to a printer if I can get it to do that?
Re: Make a PDF at the desktop?
Reply #5 - Apr 23rd, 2009, 8:38pm
 
Be it right or way off base, what works for me on OSX is for the standalone application to create the PDF and then pass it to Preview. The first task involves knowing where processing.pdf creates the file, which means knowing what folder the application is running in. That task requires System.getProperty("user.dir"), but what confused the issue is that the user.dir result is the folder that Processing is in, not the application's folder, when the application is running in the Processing IDE.

The second task requires using Runtime.getRuntime().exec as in:
Code:
Runtime.getRuntime().exec("open -a Preview " + myPDFJob); 

 as what many net research examples claims would work, but simply doing that results in "Unhandled Exception type IOException" when trying to run in the Processing IDE . The following does work. I don't know why and maybe someone can explain why.
Code:
 try{
     Runtime.getRuntime().exec("open -a Preview " + myPDFJob);
   }
   catch (IOException e){
     e.printStackTrace();
   }
Re: Make a PDF at the desktop?
Reply #6 - Apr 24th, 2009, 6:48am
 
nutmeg wrote on Apr 23rd, 2009, 8:38pm:
The first task involves knowing where processing.pdf creates the file
You can provide an absolute path to the createGraphics call.

Quote:
The second task requires using Runtime.getRuntime().exec
You can also use open().

Quote:
simply doing that results in "Unhandled Exception type IOException" when trying to run in the Processing IDE . The following does work. I don't know why and maybe someone can explain why.
It is simple: exec() wants you to handle exceptions as the message says. That's because you are not sure the program you want to run actually exists on the current system, so you must handle such exceptional () case. You add the try/catch, you handle the exception (correctly or not, that's not the problem of Java), Java is happy!  Cool
Re: Make a PDF at the desktop?
Reply #7 - Apr 27th, 2009, 7:13pm
 
Thanks PhilLo.  I think I recognize the error message now. Its at compile time and its similar to the one you get making a boolean function not knowing that there is not a default false state.
Page Index Toggle Pages: 1