添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello, so currently I am trying to print a screen. My script works and everything is good except for the zoom factor, if I used the zoom factor it zooms but also pulls my report to the right. If I use the fit to page option then it centers it but it’s too small. Is there anything I could do to help either of those, I would prefer to just be able to zoom into the window without it pulling to the right. Here’s my script:

job = system.print.createPrintJob(event.source.parent)
job.setPageHeight(11)
job.setPageWidth(8.5)
job.setZoomFactor(.65)
job.setOrientation(1)
job.print()

Can you disable the print dialog? I’ve noticed in the past that the print dialog overrides settings like paper size with some printer defaults. So not all parameters have the correct effect.

If all you want is to select the correct printer, you can fetch the printer names with some separate code, and let the user choose the printer in a dropdown.

Hmm, aparently in the past I have implemented my own printing method. I don’t remember why, but I do remember I tried to achieve my goal with the ignition print functions first.

Below is the code to get the printer names installed on the system, and write them to a dropdown or table dataset.

from java.awt.print import PrinterJob
job = PrinterJob.getPrinterJob()
services = job.lookupPrintServices()
printerNames = [[s.getName()] for s in services]
ds = system.dataset.toDataSet(["Printers"], printerNames)
event.source.parent.getComponent('cmbPrinters').data = ds

This is the code to print a number of copies of a certain container. Either by giving a printer, or by showing the printer dialog. Note that the paper size was nothing default here (it was for labels, and printer measurements were quite off), so you should probably alter that. There are some default media sizes you can find in the Java docs: https://docs.oracle.com/javase/7/docs/api/javax/print/attribute/standard/MediaSize.NA.html

printContainer(container, numCopies, printerName=None):
	from javax.swing.JTable import PrintMode
	from javax.print.attribute import HashPrintRequestAttributeSet
	from javax.print.attribute.standard import Copies
	from java.awt.print import PrinterJob
	from javax.print.attribute.standard import OrientationRequested, MediaSize
	from com.inductiveautomation.factorypmi.application.script.builtin.PrintUtilities import ComponentPrinter
	if numCopies < 1:
		return
	printable = ComponentPrinter(container, True, -1.0)
	job = PrinterJob.getPrinterJob()
	job.setPrintable(printable)
	aset = HashPrintRequestAttributeSet();
	aset.add(Copies(numCopies))
	#aset.add(OrientationRequested.LANDSCAPE);
	printer = None
	if printerName != None:
		services = job.lookupPrintServices()
		aset.add(MediaSize.findMedia(400,400, MediaSize.MM))
		printers = [s for s in services if printerName == s.getName()]
		if len(printers) > 0:
			printer = printers[0]
			job.setPrintService(printer)
		else:
			system.gui.messageBox("Printer %s not found; using default printer" % printerName)
	if printer or job.printDialog(aset):
		job.print(aset)