How to simply print a page in Processing?
for my current project, I'm looking for a really simple workaround. I do a random graphic in Processing, and when the code has finished the graphic it should print on my printer. But preferable without the dialog etc. Just print it on paper.
I was looking around the Internet and several Java forums, but I only found "overkill" tutorials. (like this: h开发者_运维问答ttp://www.javaworld.com/javaworld/jw-10-2000/jw-1020-print.html)
Is there an easy way to do this?
I've heard good things about GDSPrinting. While I've not used it and according to that page it's version 0.2, it may be a solution for you.
As has been said too many times before: Java and Printers don't get along very well. I wish you luck.
This is definitely a hack, but if you can't find what you're looking for, script taking a screenshot (keyboard command) and open a photo editor and print. http://sikuli.org/ can automate pressing buttons (like print) and you can execute external commands from Processing using open()
http://processing.org/reference/open_.html
http://sikuli.org/docx/faq/010-command-line.html
If there is no easy way to directly call the printer, you may use the java Robot class, here is an example on how to use it: How to simulate keyboard presses in java?
I'm answering this 8 years late, but hopefully it helps anyone who finds this thread.
First save the image / frame that you want to print with a definite path:
save(“image_to_print.png”);
Then add this method to your sketch:
void printImage(String path) {
Process p = exec("lp", path);
try {
int result = p.waitFor();
println("the process returned " + result);
}
catch (InterruptedException e) {
println("error : " + e);
}
}
Now just call the method with the relevant filename and path:
printImage("/Users/me/Desktop/printDemo/image_to_print.png");
It's the equivalent of running the following in your command line interface:
lp image_to_print.txt
Here's a medium post explaining this.
精彩评论