# Print to specific printer

**URL:** <https://forum.inductiveautomation.com/t/print-to-specific-printer/7990>\
**Category:** Ignition\
**Created:** [February 12, 2014, 3:01am UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990 "2014-02-12T03:01:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cja7928](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cja7928](https://forum.inductiveautomation.com/u/cja7928)\
**Post date:** [February 12, 2014, 3:01am UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/1 "2014-02-12T03:01:21Z")

</div>

I need to be able to send print jobs to different printers without the operator having to choose which one - avoid sending to wrong printer…

I saw this on another thread:

` job.setPrinterName("the_printer_name")
`

but when I try it I get this:

[code]Traceback (most recent call last):

File “event:mouseClicked”, line 2, in

AttributeError: ‘[com.inductiveautomation.factorypmi.application.com](http://com.inductiveautomation.factorypmi.application.com)’ object has no attribute ‘setPrinterName’

Ignition v7.6.4 (b2013112117)  
Java: Sun Microsystems Inc. 1.6.0\_31  
[/code]

Is there something Im missing or Is there a way to force a print job to a specific printer or set the default printer for that job?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![hazelchr](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@hazelchr](https://forum.inductiveautomation.com/u/hazelchr)\
**Post date:** [February 14, 2014, 9:29pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/2 "2014-02-14T21:29:24Z")

</div>

I haven’t played with the code for it, but it looks like importing the java.awt.print class might be of use to you.

java.awt.print.PrinterJob class:  
[http://docs.oracle.com/javase/7/docs/api/java/awt/print/PrinterJob.html](http://docs.oracle.com/javase/7/docs/api/java/awt/print/PrinterJob.html)

maybe the .setPrintService() method would be helpful…

---

<div class="post-metadata">

**Author:** ![cja7928](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cja7928](https://forum.inductiveautomation.com/u/cja7928)\
**Post date:** [February 17, 2014, 8:06pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/3 "2014-02-17T20:06:31Z")

</div>

Is there a reason job.setPrinterName(“the\_printer\_name”) doesnt work?

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [February 18, 2014, 3:35pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/4 "2014-02-18T15:35:41Z")

</div>

You must have something else going on, and may need to call tech support to see what’s happening.

I just tried the following script in 7.6.4

`job = system.print.createPrintJob(event.source.parent)
print dir(job)
print "Printer name is: ",job.getPrinterName()
job.setPrinterName("foo")
print "After setting, printer name is: ",job.getPrinterName()`

My output was:

`[' __class__', ' __copy__', ' __deepcopy__', ' __delattr__', ' __doc__', ' __eq__', ' __getattribute__', ' __hash__', ' __init__', ' __ne__', ' __new__', ' __reduce__', ' __reduce_ex__', ' __repr__', ' __setattr__', ' __str__', ' __unicode__', 'bottomMargin', 'class', 'equals', 'fitToPage', 'getBottomMargin', 'getClass', 'getLeftMargin', 'getOrientation', 'getPageHeight', 'getPageWidth', 'getPrinterName', 'getRightMargin', 'getTopMargin', 'getZoomFactor', 'hashCode', 'isFitToPage', 'isShowPrintDialog', 'leftMargin', 'margins', 'notify', 'notifyAll', 'orientation', 'pageHeight', 'pageWidth', 'print', 'printerName', 'rightMargin', 'setBottomMargin', 'setFitToPage', 'setLeftMargin', 'setMargins', 'setOrientation', 'setPageHeight', 'setPageWidth', 'setPrinterName', 'setRightMargin', 'setShowPageFormat', 'setShowPrintDialog', 'setTopMargin', 'setZoomFactor', 'showPageFormat', 'showPrintDialog', 'toString', 'topMargin', 'wait', 'zoomFactor']
Printer name is: None
After setting, printer name is: foo
`

The script above was my complete script – no special imports.

---

<div class="post-metadata">

**Author:** ![cja7928](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cja7928](https://forum.inductiveautomation.com/u/cja7928)\
**Post date:** [February 18, 2014, 4:30pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/5 "2014-02-18T16:30:20Z")

</div>

hmmm… interesting. I tried it again:

`job = event.source.parent.getComponent('ConvLocData_Table')
job.setPrinterName("SSBINV05")
job.print()`

but I get the error object has no attribute. Im running 7.6.4 wonder what could be wrong. seems like a fairly simple instruction.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [February 18, 2014, 4:38pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/6 "2014-02-18T16:38:21Z")

</div>

Take a look at the first line of each of our scripts. You aren’t calling the function on a printjob object.

---

<div class="post-metadata">

**Author:** ![cja7928](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cja7928](https://forum.inductiveautomation.com/u/cja7928)\
**Post date:** [February 18, 2014, 5:38pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/7 "2014-02-18T17:38:19Z")

</div>

ahh. got it - thank you. I overlooked that. since it worked without the setPrinterName I wasnt paying attention to that first line in your reply.

when I use createPrintJob `job = system.print.createPrintJob(event.source.parent.getComponent('ConvLocData_Table').data)`

it errors with “1st arg cant be coerced to java.awt.Component”

but when I put it in as you have it, it works - just doesnt print the chart it prints the entire screen shot.

also as far as the setPrinterName Ive tried both the printer name and the full path ie: “\networkloc\myprinter” Ive tried a number of things and everything ive tried gives an error “no compatible printer found”

sorry for all the questions - thanks for your help.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [February 18, 2014, 5:56pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/8 "2014-02-18T17:56:20Z")

</div>

For the first problem, remove the ‘.data’ from your parameter. You’re grabbing the dataset, when what you want is the component.

My setup here isn’t easy to test the printer path, but I’d suggest you try the full pathname again ("\networkloc\myprinter" ), except this time escape the backslash characters. You can either change the string to “\\networkloc\myprinter” or add an r in front ( r"\networkloc\myprinter" ). These both tell Python that you really want a backslash, not special characters. Let me know if that helps.

---

<div class="post-metadata">

**Author:** ![cja7928](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cja7928](https://forum.inductiveautomation.com/u/cja7928)\
**Post date:** [February 18, 2014, 6:47pm UTC](https://forum.inductiveautomation.com/t/print-to-specific-printer/7990/9 "2014-02-18T18:47:28Z")

</div>

thats it!. r’\networkloc\myprinter’ did the trick. -thank you

removing the .data and going with:

```auto
job = system.print.createPrintJob(event.source.parent.getComponent('ConvLocData_Table'))
```

did work in printing just the chart the only. the nice thing about using

`job = (event.source.parent.getComponent('ConvLocData_Table').data)
job.print()`

is that it will print the whole charts entire data and not just whats visible in the window but maybe nothing I can do about that if I want to be able to select which printer.

Thanks again for your help.
