Power Table printing, fit to page

I am able to print the power table with the script below with a mouse click but it is very hard to see. Is there away to fit it to the page so it is more readable?

# Get a reference to the power table
powerTable = event.source.parent.getComponent("Power Table") # Get a reference to the table

Has anyone done this before in scripting? or I found this. (.setFitToPage) But I am not for sure how to add it.

Try using system.print.createPrintJob() instead of your table’s .print() method.

{ Edit: s/util/print/ }

I get this error

Traceback (most recent call last):

  File "<event:actionPerformed>", line 4, in <module>

AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'createPrintJob'

Script I tried

powerTable = system.util.createPrintJob(event.source.parent.getComponent("Power Table"))

Sorry, typo. Lesson: use the linked examples, not the typo in my post. Take note of that error message – it usually means a typo in a function name. I also don’t recommend you keep the “powerTable” variable name for a print job – not if you want to understand this code when you revisit it next year.

I got it to work with the script from the link but this is what it prints. It cuts it off and doesn’t fit it to the page.

Here is the script i am using

job = system.print.createPrintJob(event.source.parent.getComponent('Power Table'))

I would expect fit-to-page and zoom factor to be contradictory. Since zoom is later in your code, it seems to have overridden the fit-to-page option.

with zoom commented out it shows the full powertable from side to side when you print it but it doesn’t fit it to the full page length wise

even if I take every thing out of the code like this it still doesn’t fit it to the page

job = system.print.createPrintJob(event.source.parent.getComponent('Power Table'))

The system.print function doesn’t perform layout again (I believe) - so the print job will keep the same aspect ratio as whatever client is actively rendering it/however it was laid out in the designer. It will scale one axis to fit (in this case width) but not reflow the contents to fit vertically. This is just a limitation of the system.print functions. You may need to look into the reporting module if you need dynamic printouts of data.