# Email pdf Reports From client

**URL:** <https://forum.inductiveautomation.com/t/email-pdf-reports-from-client/2956>\
**Category:** Ignition\
**Created:** [May 19, 2011, 7:24pm UTC](https://forum.inductiveautomation.com/t/email-pdf-reports-from-client/2956 "2011-05-19T19:24:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dodonnell999](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@Dodonnell999](https://forum.inductiveautomation.com/u/Dodonnell999)\
**Post date:** [May 19, 2011, 7:24pm UTC](https://forum.inductiveautomation.com/t/email-pdf-reports-from-client/2956/1 "2011-05-19T19:24:57Z")

</div>

We have an Ignition system that has reports automatically generated by a client running on the gateway server. There us a pdf viewer set up on the client to view the generated reports via the IIS setup on the gateway server.  
Now the client wants a button on the report viewer window to allow any user to email the viewed report to anyone. I’ve tried using the emailing script but the getFileAsBytes() function doesn’t seem to work with the “[http://website/](http://website/)…/filename.pdf” file path.  
Is there any way of retrieving the pdf file from the gateway and emailing it?

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [May 19, 2011, 11:05pm UTC](https://forum.inductiveautomation.com/t/email-pdf-reports-from-client/2956/2 "2011-05-19T23:05:03Z")

</div>

Add the following code to [app.net](http://app.net)

[code]def getStream(url):  
from [java.net](http://java.net) import URL  
con = URL(url).openConnection()  
con.setRequestMethod(“GET”)  
con.setDoOutput(0)  
con.setDoInput(1)  
stream = con.getInputStream()  
return stream

def streamToBytes(stream):  
bytes = []  
byte = stream.read()  
while byte != -1:  
bytes.append(byte)  
byte = stream.read()  
return bytes

def getBytesArray(bytes):  
from jarray import array

```
return array(bytes,"b")

```

def httpGetBytes(url):  
from [app.net](http://app.net) import getStream,streamToBytes,getBytesArray  
try:  
stream = getStream(url)  
bytes = streamToBytes(stream)  
stream.close()  
bytesArray = getBytesArray(bytes)  
return bytesArray  
except:  
return None[/code]

Now, in your script, to get the bytes for your attachment, just run `attachmentBytes = app.net.httpGetBytes("http://someurl.com/file.pdf")`

---

<div class="post-metadata">

**Author:** ![Dodonnell999](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@Dodonnell999](https://forum.inductiveautomation.com/u/Dodonnell999)\
**Post date:** [May 20, 2011, 8:28am UTC](https://forum.inductiveautomation.com/t/email-pdf-reports-from-client/2956/3 "2011-05-20T08:28:42Z")

</div>

Thanks for that Kyle, it worked a treat!

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [December 12, 2012, 11:50pm UTC](https://forum.inductiveautomation.com/t/email-pdf-reports-from-client/2956/4 "2012-12-12T23:50:32Z")

</div>

I’m not sure why I’m having a problem with this script but it seems to stem from the java read() function. The documentation says that this method “reads an unsigned byte from the input stream and returns an int between 0 and 255”. Now the problem I have is that the Jython array function (code = return array(bytes, “b”)) expects the bytes to be signed bytes (-128 to 127). As a result when i pass in the PyList that is created using the read() function I get an error that says the “value is too large for a byte.” I’ve spent a good portion of the day trying to figure out how to fix this to no avail. About ready to throw the computer through the window. Would appreciate any help. Thank you.

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [December 14, 2012, 6:24pm UTC](https://forum.inductiveautomation.com/t/email-pdf-reports-from-client/2956/5 "2012-12-14T18:24:19Z")

</div>

I can see why you’re confused! I recommend adding print statements to the streamToBytes() function to see what exactly is being appended into the array. Once you know that, you should be able to track down the problem.
