Email pdf Reports From client

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/…/filename.pdf” file path.
Is there any way of retrieving the pdf file from the gateway and emailing it?

Add the following code to

[code]def getStream(url):
from import URL
con = URL(url).openConnection()
stream = con.getInputStream()
return stream

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

def getBytesArray(bytes):
from jarray import array

return array(bytes,"b")

def httpGetBytes(url):
from import getStream,streamToBytes,getBytesArray
stream = getStream(url)
bytes = streamToBytes(stream)
bytesArray = getBytesArray(bytes)
return bytesArray
return None[/code]

Now, in your script, to get the bytes for your attachment, just run attachmentBytes ="")

Thanks for that Kyle, it worked a treat!

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.

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.