Automatic PDF Printing

Hello! I am trying to set a screen to pop up and give the option to save as a pdf, I have the script that works but I am just not sure how to make this script run at a certain time of day, any help is much appreciated thank you!

	system.nav.openWindow("Analog Report1")
	obj = system.gui.getWindow("Analog Report1")
	printJob = system.print.createPrintJob(obj) 
	printJob.showPrintDialog = 0
	printJob.orientation = system.print.PORTRAIT
	printJob.leftMargin=.05
	printJob.rightMargin=.05
	printJob.topMargin=.05
	printJob.bottomMargin=.05
	printJob.print()

Is the report being generated from Ignition's report module, or is it simply a loaded PDF?

It is printing a pdf from a screen in vision, I have just found that you can use something like the following code inside of a timer client event to force the screen to popup and give the user the option to save, do you know if it is possible to save the pdf without having someone come and type in the name of the pdf and save it manually?

curTime = system.date.format(system.date.now(),"HH:mm:ss")
					
if curTime == "12:03:00":
					
		system.nav.openWindow("Analog Report1")
		obj = system.gui.getWindow("Analog Report1")
		printJob = system.print.createPrintJob(obj) 
		printJob.showPrintDialog = 0
		printJob.orientation = system.print.PORTRAIT
		printJob.leftMargin=.05
		printJob.rightMargin=.05
		printJob.topMargin=.05
		printJob.bottomMargin=.05
		printJob.print()
		system.nav.closeWindow(obj)

You are printing to a PDF "printer", which is outside Ignition. So, no.

You should use the Reporting Module to make PDFs.

2 Likes

Is there a different way to save as a pdf that would allow you to do this other than the reporting module?

PDF, no. You could render the window to a BufferedImage and save that image to a file.

1 Like

Thank you for your help!

So something like this?

curDate = system.date.format(system.date.now(),"MM:dd:yyyy")
system.nav.openWindow("Analog Report1")
obj = system.gui.getWindow("Analog Report1")
path="C:\\Users\\chunter\\Desktop\\Norcross Scripts\\Test\\Test.png"
			
			# If the path is not None...
if path != None:
			    #Save the file
	system.print.printToImage(obj, path)
			    
system.nav.closeWindow(obj)

Also, I tried to do something like this, but it did not allow the print to happen just stating "IIOException: Can't create an ImageOutputStream!" Is my formatting incorrect?

path="C:\\Users\\chunter\\Desktop\\Norcross Scripts\\Test\\"+curDate+"_Test.png"

It completely slipped my mind that you cannot have colons in file names :expressionless: