Printing multiple Vision Client pages in one print job

I wish to print the pages (of type com.inductiveautomation.factorypmi.application.FPMIWindow) that I created in ignition in one single print job, as consecutive pages. Using createPrintJob, I am able to choose only one page per print job. Is there a straightforward way of achieving this by using Jython scripting?

No.

You’ll probably have to create your own print job; we don’t expose enough of JythonPrintJob to really do this.

Hello PGriffith,

Thank you for the quick response!

I took your advice and created a printerjob

book = Book()

P1 = system.gui.getWindow('P1')
P2 = system.gui.getWindow('P2')

printable1 = ComponentPrinter(P1, True, -1)
printable2 = ComponentPrinter(P2, True, -1)

job = PrinterJob.getPrinterJob()
pf = job.defaultPage()

# Create a letter sized piece of paper with one inch margins
paper = Paper()

# resize the paper and the imageable area
width = P1.getWidth()
height = P1.getHeight()
paper.setSize(width, height)
paper.setImageableArea(0, 0, width, height)

# set paper for the pageFormat
pf.setPaper(paper)

bk = Book()
bk.append(printable1, pf)
bk.append(printable2, pf)

job.setPageable(bk)
e = PrinterException()

if job.printDialog():
    try:
        job.print()
    except e:
        print "FAILED!"

This prints the PDF, but only the first page that is appended to the book. Explicitly specifying the number of pages while appending to the Book does not help.

I am stuck with this problem for weeks, it would be EPIC if I could find a solution!

Regards

Hm, at a glance that definitely seems correct. Does the book return the correct number of pages after you’ve appended both components?
https://docs.oracle.com/javase/7/docs/api/java/awt/print/Book.html#getNumberOfPages()

image
The number of pages returns exactly the number of printables (components) I append to the Book. This number is also visible at the print dialog. But the final document, that is printed using this logic, has only the first page.

Also, trying to print only the second page using the print dialog creates the xps file and then deletes it automatically.

Oh, boo. I didn’t notice; ComponentPrinter has a check at the beginning of its print method that aborts if the page index requested is not 0.

You’ll have to make your own ComponentPrinter-like; I tried monkey-patching print to always use page 0, but couldn’t get it to work:

from __future__ import print_function
from java.awt.print import Book, Paper, PrinterJob
from com.inductiveautomation.factorypmi.application.script.builtin.PrintUtilities import ComponentPrinter

book = Book()

P1 = system.gui.getWindow('pta')
P2 = system.gui.getWindow('treefont')

class MultipleComponentPrinter(ComponentPrinter):
	def print(self, graphics, format, pageIndex):
		ComponentPrinter.print(self, graphics, format, 0)

printable1 = MultipleComponentPrinter(P1, True, -1)
printable2 = MultipleComponentPrinter(P2, True, -1)

job = PrinterJob.getPrinterJob()
pf = job.defaultPage()

# Create a letter sized piece of paper with one inch margins
paper = Paper()

# resize the paper and the imageable area
width = P1.getWidth()
height = P1.getHeight()
paper.setSize(width, height)
paper.setImageableArea(0, 0, width, height)

# set paper for the pageFormat
pf.setPaper(paper)

bk = Book()
bk.append(printable1, pf)
bk.append(printable2, pf)

job.setPageable(bk)

if job.printDialog():
    job.print()
1 Like