Send PDF Via Email

Hi There,

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?

https://docs.inductiveautomation.com/display/DOC81/system.report.executeAndDistribute

@Matrix_Engineering : The issue is, report is saved as pdf and not really executing a report. so basically the file client is viewing is a pdf file from gateway. which has http address.

how do I get getbytes then?

I'm assuming you have the webdev module or some file hosting server available if you are sourcing the PDF file from a web address.

In either case, find out where the files are actually stored, and see if the gateway can reach that file location. getFileAsBytes is expecting a filesystem path (think /mnt/usr or C:/users/ or //sharedFileServer/folder/) and probably wont work with a web address.

How are your users determining which report to view? Does the system just fetch the latest?

You can probably use a httpClient instance to make a Get request to the URL the pdf viewer is using, and then use the response.body as the source of the bytes to attach to the email.

@ryan.white
is a fileserver on gateway. URL contain address like folllowing
https://0.0.0.0:0000/Pdfs/filename.pdf
I am actually using in-lineFrame to show this pdf file.
I am not able to retrieve with http get method can you please give an example?

it says : Invalid URL - Illegal character in path

How is the iframe getting its URL, from the user navigating inside of it or is something else in the session/page supplying the URL? Do you have any spaces/funky characters in the filename?

The script to fetch the file data from the URL should be something along the lines of the following, placed into a project level script. Then call the fetchResourceHTTP method from where ever you have the script to get the file data and send the email.

I have confirmed that it works for a webdev endpoint we have on our ignition gateway using both the gateway IP and the gateway hostname.

from java.lang import Throwable

logger = system.util.getLogger("MyLoggerNameHere." + __name__)

# Define httpclient at top level
fileFetcherClient = system.net.httpClient()


def fetchResourceHTTP(resourceURL):

	try:
		fileServerResponse = fileFetcherClient.get(resourceURL)

	except Throwable, t:
		logger.warn("Java error performing GET", t)
		return None

	if fileServerResponse.good:
		fileByteData = fileServerResponse.body
		return fileByteData

	else:
		logger.warnf("Received status code %d", fileServerResponse.statusCode)
		return None

You also mention the reports are being generated by a client on the gateway, does this mean you have a scheduled report or is it triggered from tag change event script or similar? If it is a scheduled report or something in a gateway script, find out where it is saving it to.

I used resource = client.get (url) and then return resource.body as a reference for bytes! Worked out perfect. Thank you so much!