system.print.createPrintJob with File Name

Can a name be auto-populated (such as date/time) into the system.print.createPrintJob function? This would allow the file to be saved without using the PrintDialog popup.

Unfortunately, no. However, if you are just trying to save a snapshot of a component to a file, you can create a BufferedImage of the desired resolution, use myComponent.paint(bufimage.getGraphics()) to render the component into the image, then use ImageIO to save the rendered image to a file.

1 Like

Thanks @pturmel, would the resulting file have to be saved as an image type?

Yes. You might also investigate using Java’s PrintJob class yourself (a bit of a pain, iirc).

1 Like

If you are just looking to print screen to a file you could use something like this.
We use it to email screenshots from the operators to support.

def saveScreenshot(twindow):
	from java.io import File
	from java.awt.image import BufferedImage
	from javax.imageio import ImageIO
	from java.awt import Robot
	from java.awt import Rectangle
	from java.awt import Toolkit
	import system
	problem = system.gui.inputBox('Enter a short description of the problem and click OK','Problem Report')
	home = system.util.getProperty("user.home")
	BufferedImage = Robot().createScreenCapture(Rectangle(Toolkit.getDefaultToolkit().getScreenSize()))
	temp = File(home + "/Documents/" + twindow + ".png");
	temp.mkdirs()
	ImageIO.write(BufferedImage, "png", temp)

It will create a png screenshot in the users home directory.
You can modify it to save wherever with whatever name you want.

1 Like