如何在Processing中简单地打印一页?

发布于 2024-11-23 19:26:32 字数 325 浏览 1 评论 0原文

对于我当前的项目,我正在寻找一种非常简单的解决方法。我在处理中制作随机图形,当代码完成图形后,它应该在我的打印机上打印。但最好没有对话框等。只需将其打印在纸上即可。

我浏览了互联网和几个 Java 论坛,但我只找到了“矫枉过正”的教程。 (像这样: http://www.javaworld.com /javaworld/jw-10-2000/jw-1020-print.html

有一个简单的方法来做到这一点吗?

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: http://www.javaworld.com/javaworld/jw-10-2000/jw-1020-print.html)

Is there an easy way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

生死何惧 2024-11-30 19:26:32

我听说过有关 GDSPrinting 的好消息。虽然我没有使用过它,并且根据该页面,它的版本是 0.2,但它可能是适合您的解决方案。

正如之前多次说过的那样:Java 和打印机相处得不太好。
祝你好运。

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.

阳光①夏 2024-11-30 19:26:32

这绝对是一种黑客攻击,但如果您找不到所需的内容,请编写脚本截取屏幕截图(键盘命令)并打开照片编辑器并打印。 http://sikuli.org/ 可以自动按下按钮(如打印),并且您可以使用 open 从处理中执行外部命令()

http://processing.org/reference/open_.html

http://sikuli.org/docx/faq/010-command-line.html

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

魄砕の薆 2024-11-30 19:26:32

如果没有简单的方法直接调用打印机,您可以使用java Robot类,这里有一个如何使用它的示例:如何在java中模拟键盘按下?

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?

尐籹人 2024-11-30 19:26:32

我晚了 8 年才回答这个问题,但希望它对找到这个帖子的人有所帮助。

首先使用明确的路径保存要打印的图像/帧:

save(“image_to_print.png”);

然后将此方法添加到您的草图中:

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);
  }
}

现在只需使用相关的文件名和路径调用该方法:

printImage("/Users/me/Desktop/printDemo/image_to_print.png");

这相当于在命令行界面中运行以下命令:

lp image_to_print.txt

这是中等帖子解释了这一点

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文