# Negative Width Error when Printing Template Canvas

**URL:** <https://forum.inductiveautomation.com/t/negative-width-error-when-printing-template-canvas/98025>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [October 31, 2024, 11:56pm UTC](https://forum.inductiveautomation.com/t/negative-width-error-when-printing-template-canvas/98025 "2024-10-31T23:56:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Viksne](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Michael\_Viksne](https://forum.inductiveautomation.com/u/Michael_Viksne)\
**Post date:** [October 31, 2024, 11:56pm UTC](https://forum.inductiveautomation.com/t/negative-width-error-when-printing-template-canvas/98025/1 "2024-10-31T23:56:22Z")

</div>

Hello All,

I am trying to print the contents of a template canvas and I am receiving an Illegal Argument error **only** when attempting to print in portrait. No errors occur when printing landscape. I have the full error below.

I have tried re-sizing the template canvas and some other simple things with no success.

Any help is much appreciated.

```python
java.lang.IllegalArgumentException: negative width
	at java.desktop/java.awt.BasicStroke.<init>(Unknown Source)
	at java.desktop/java.awt.BasicStroke.<init>(Unknown Source)
	at java.desktop/javax.swing.border.EtchedBorder.paintBorder(Unknown Source)
	at java.desktop/javax.swing.JComponent.paintBorder(Unknown Source)
	at java.desktop/javax.swing.JComponent.paint(Unknown Source)
	at com.inductiveautomation.factorypmi.application.script.builtin.PrintUtilities$ComponentPrinter.print(PrintUtilities.java:293)
	at java.desktop/sun.print.RasterPrinterJob.printPage(Unknown Source)
	at java.desktop/sun.print.RasterPrinterJob.print(Unknown Source)
	at com.inductiveautomation.factorypmi.application.print.FPMIPrinterJob.print(FPMIPrinterJob.java:400)
	at com.inductiveautomation.factorypmi.application.script.builtin.PrintUtilities$JythonPrintJob.print(PrintUtilities.java:129)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)
	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:208)
	at org.python.core.PyObject. __call__ (PyObject.java:461)
	at org.python.core.PyObject. __call__ (PyObject.java:465)
	at org.python.core.PyMethod. __call__ (PyMethod.java:126)
	at org.python.pycode._pyx120.f$0(<event:actionPerformed>:18)
	at org.python.pycode._pyx120.call_function(<event:actionPerformed>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1703)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:804)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:207)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:300)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at jdk.proxy2/jdk.proxy2.$Proxy61.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
	at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Container.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at com.inductiveautomation.snap.swing.RibsEventQueue.dispatchEvent(RibsEventQueue.java:99)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Ignition v8.1.42 (b2024061810)
Java: Azul Systems, Inc. 17.0.11

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 1, 2024, 8:10am UTC](https://forum.inductiveautomation.com/t/negative-width-error-when-printing-template-canvas/98025/2 "2024-11-01T08:10:52Z")

</div>

Printing a test canvas from a button using landscape mode worked as expected with this code:

```python
canvas = event.source.parent.getComponent('Template Canvas')

# Pass the canvas to be printed into the createPrintJob utility function
job = system.print.createPrintJob(canvas)

# Decide whether or not to show the print dialog
# ...to give the user the opertunity to access options like changing printers or printing multiples
job.setShowPrintDialog(False)

# Set the margines to zero in an effort to maximize print size
job.setMargins(0)

# Set the print orientation: 0 = Landscape, 1 = Portrait
job.setOrientation(False)

# Execute the printer call
job.print()

```

Could you provide more details about your implementation? What layout are you using in your canvas? Is there overflow (scroll bars present)? Does your script differ in some way from mine, or are you using some other print method?

---

<div class="post-metadata">

**Author:** ![Michael\_Viksne](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Michael\_Viksne](https://forum.inductiveautomation.com/u/Michael_Viksne)\
**Post date:** [November 1, 2024, 4:54pm UTC](https://forum.inductiveautomation.com/t/negative-width-error-when-printing-template-canvas/98025/3 "2024-11-01T16:54:01Z")

</div>

I think I may have solved the issue by eliminating the border on the template canvas. If I have some time I will see if I can make it work with the border still there.

For completeness, here is the script I was originally using:

```python
job = system.print.createPrintJob(event.source.parent.getComponent('Template Canvas'))
job.setShowPrintDialog(0)
job.setPageHeight(11)
job.setPageWidth(8.5)
job.setMargins(.5)
job.setOrientation(1)
job.setFitToPage(1)
job.print()

```

Switching to using the test script led to the same error.

---

<div class="post-metadata">

**Author:** ![avaughn](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/avaughn/32/38972_2.png) [@avaughn](https://forum.inductiveautomation.com/u/avaughn)\
**Post date:** [November 1, 2024, 5:57pm UTC](https://forum.inductiveautomation.com/t/negative-width-error-when-printing-template-canvas/98025/4 "2024-11-01T17:57:01Z")

</div>

This is a known issue that resulted from the move to Java 17. Using any border other than an etched border should allow this to still work.
