Printscreen

I would like to put a Printscreen button to print all of the open windows. I will have three windows open at any given time. A “Page North” header at the top of the screen, a “Page South” set of Tabs at the bottom of the screen, and then another open window between the two.

This script only prints the window the button is in.

job = system.print.createPrintJob(event.source.parent)
job.setMargins(0.5)
job.zoomFactor = 0.0
job.showPageFormat = 0
job.orientation = system.print.LANDSCAPE
job.print()

How do I script to print the three windows as they appear on the screen?

This will take a screenshot and print to the default printer.

from java.awt import Toolkit, Robot, Rectangle
from javax.imageio import ImageIO
from java.io import File, ByteArrayOutputStream

from javax.print import Doc, DocFlavor, DocPrintJob, PrintService, PrintServiceLookup, SimpleDoc
from javax.print.attribute import HashPrintRequestAttributeSet, HashDocAttributeSet
from javax.print.attribute.standard import Copies, OrientationRequested

#Capture Screen
tk = Toolkit.getDefaultToolkit()
ss = tk.getScreenSize()
rbt = Robot()
bimage = rbt.createScreenCapture(Rectangle(ss)) 

#Convert Screen Cap to Byte Array so we can print it.
baos=ByteArrayOutputStream()                     
ImageIO.write(bimage, "png", baos)
baos.flush
byteArray=baos.toByteArray()
baos.close

#Set Printjob Attributes
printJobAttributeSet = HashPrintRequestAttributeSet()
DocAttributeSet = HashDocAttributeSet()
printJobAttributeSet.add(Copies(1))
printJobAttributeSet.add(OrientationRequested.LANDSCAPE)

#Get default Printer
service=PrintServiceLookup.lookupDefaultPrintService()

#Create Printjob
job=service.createPrintJob()

#Create document
doc=SimpleDoc(byteArray, DocFlavor.BYTE_ARRAY.PNG, DocAttributeSet)

#Print Document
job.print(doc, printJobAttributeSet)
print "Done!"
1 Like

If you didn’t want it to automatically print but have the printer options pop up. Do you know what changes you need to make to the above code?