# How to print a PDF from a gateway script

**URL:** <https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [September 10, 2020, 5:58pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565 "2020-09-10T17:58:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 5:58pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/1 "2020-09-10T17:58:50Z")

</div>

How to print a PDF from a gateway script based on a tags value.

````auto
import system

if system.tag.read ("Test123").value ==1:
	job =system.print.createPrintJob('\\amifile\Departments\Work Instructions and Procedures\Forms\QD 711 Daily Air Compressors Checklist.PDF')
	job.setPrinterName('PLC-Office')
	job.setShowPrintDialog(0)
	job.setPageHeight(5)
	job.setPageWidth(5)
	job.setMargins(.5)
	job.setOrientation(1)
	job.print()
	
	```
````

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [September 10, 2020, 6:06pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/2 "2020-09-10T18:06:09Z")

</div>

You tag path must include the tag provider when called in the GW scope.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 6:11pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/3 "2020-09-10T18:11:13Z")

</div>

I added the tag provider but it still doesn’t print

```auto
import system

if system.tag.read ("[default]Test123").value ==1:
	job =system.print.createPrintJob('\\amifile\Departments\Work Instructions and Procedures\Forms\QD 711 Daily Air Compressors Checklist.PDF')
	job.setPrinterName('PLC-Office')
	job.setShowPrintDialog(0)
	job.setPageHeight(5)
	job.setPageWidth(5)
	job.setMargins(.5)
	job.setOrientation(1)
	job.print()
	
	

```

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [September 10, 2020, 6:32pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/4 "2020-09-10T18:32:49Z")

</div>

Does the Ignition gateway server have a Printer installed on it called _PLC-Office_ ? Also, you’ll have to make sure the Ignition service has access to the shared file as well. You didn’t specify much about your setup so I’ll assume you’re using Windows 10; out the box Ignition installs will use the SYSTEM user which probably won’t be able to read the PDF in the file path. Another thing to point out is the file path for every **\** you need an extra one to escape it.

new path:

```auto
\\\\amifile\\Departments\\Work Instructions and Procedures\\Forms\\QD 711 Daily Air Compressors Checklist.PDF

```

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 6:34pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/5 "2020-09-10T18:34:20Z")

</div>

I have printed the same file path from the pdf viewer. I will check on the access for the printer.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [September 10, 2020, 6:36pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/6 "2020-09-10T18:36:01Z")

</div>

There’s a big difference here. Another thing to note is the createPrintJob function required a component object and your passing a filepath.

[https://docs.inductiveautomation.com/display/DOC79/system.print.createPrintJob](https://docs.inductiveautomation.com/display/DOC79/system.print.createPrintJob)

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 6:38pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/7 "2020-09-10T18:38:47Z")

</div>

I agree with you. Is there documentation for printing from the gateway and not a component? I was testing the script how it was to see if it could work.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [September 10, 2020, 6:40pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/8 "2020-09-10T18:40:13Z")

</div>

I haven’t tried to print a file from the network before but I don’t think it will work the way your doing it. the createPrintJob function is looking for a component. Your passing it a string which I’m sure is the location of the file you want to print but I doubt it will open the file from the string.

The easiest way I could see doing it is by using the PDF viewer. You could have it hidden on a screen or open a popup with it to load the PDF and print it, then close it again. Easiest I would think would be having the object hidden on the screen. Using the .loadPDFBytes function to put your PDF into the viewer, then use the .print function to print it. You would need to use the [system.file.readFileAsBytes()](https://docs.inductiveautomation.com/display/DOC79/system.file.readFileAsBytes) function to turn your pdf into the bytes needed by the PDF viewer. If you set the showDialog in your .print call to false, I would assume that it will use the clients default printer.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [September 10, 2020, 6:41pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/9 "2020-09-10T18:41:01Z")

</div>

I’ve only ever printed Ignition reports from the gateway. Not a file per se.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 6:42pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/10 "2020-09-10T18:42:51Z")

</div>

I have printed from the PDF viewer as will a components (tables etc)

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 6:43pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/11 "2020-09-10T18:43:47Z")

</div>

I will keep digging

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 6:56pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/12 "2020-09-10T18:56:56Z")

</div>

I looked through the gateway logs. I get a error saying print has no attribute

```auto
Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 4, in AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'print'

... 13 common frames omitted

```

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [September 10, 2020, 7:00pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/13 "2020-09-10T19:00:28Z")

</div>

If your still using:

```auto
job =system.print.createPrintJob('\\amifile\Departments\Work Instructions and Procedures\Forms\QD 711 Daily Air Compressors Checklist.PDF')

```

Then it will keep giving you that error. ‘\amifile\Departments\Work Instructions and Procedures\Forms\QD 711 Daily Air Compressors Checklist.PDF’ is a string instead of an object so it won’t have a print attribute.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 10, 2020, 7:02pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/14 "2020-09-10T19:02:44Z")

</div>

These `system.print` functions are scoped to Vision Client only.

I don’t know if you can print from the gateway scope without using report module’s `system.report.executeAndDistribute` on a report.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 7:12pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/15 "2020-09-10T19:12:25Z")

</div>

So I can print from a PDF viewer from a script

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 10, 2020, 7:13pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/16 "2020-09-10T19:13:50Z")

</div>

Yes. Yes?

Was that a question? 🙂

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 7:25pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/17 "2020-09-10T19:25:09Z")

</div>

so how do I go about doing that? I have a window with the pdf viewer on it already with the same file path

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 10, 2020, 7:34pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/18 "2020-09-10T19:34:54Z")

</div>

You can’t do this from the gateway. You have to use the `.print()` method on the component.

[https://docs.inductiveautomation.com/display/DOC79/PDF+Viewer](https://docs.inductiveautomation.com/display/DOC79/PDF+Viewer)

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 10, 2020, 7:38pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/19 "2020-09-10T19:38:59Z")

</div>

How do I print from the gateway script?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 10, 2020, 7:51pm UTC](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565/20 "2020-09-10T19:51:08Z")

</div>

You can’t, at least not within Ignition’s supported methods. The supported method is to use the Reporting Module.

You might be able to dig around in Java’s print engine to do this, but I haven’t seen anyone do so. Start here:  
[https://docs.oracle.com/javase/8/docs/technotes/guides/jps/index.html](https://docs.oracle.com/javase/8/docs/technotes/guides/jps/index.html)

[Next page](https://forum.inductiveautomation.com/t/how-to-print-a-pdf-from-a-gateway-script/38565.md?page=2)
