web stats
Test for presence of PDF file - Mirth Community

Go Back   Mirth Community > Mirth Connect > General Discussion

Thread Tools Display Modes
Old 08-08-2018, 08:00 AM
mcampanella@rimirad.com mcampanella@rimirad.com is offline
Mirth Newb
Join Date: Apr 2009
Location: RI
Posts: 12
mcampanella@rimirad.com is on a distinguished road
Default Test for presence of PDF file


I found this code from a previous post that can go into a deploy script to read in a PDF file;

globalChannelMap.put('pdf', FileUtil.encode(FileUtil.readBytes('/path/to/pdf')));

I would like to use this to send the pdf data as an attachment in an SMTP sender

The problem is there wont always be a pdf created in a previous step. The pdf will only be created in some instances

How can I test to make sure the PDF exists before sending the email out?

Reply With Quote
Old 11-03-2018, 06:58 AM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road

I believe that code will error if the pdf does not exist and the channel will fail to start.

When you say "there wont always be a pdf created in a previous step" do actually mean before the channel is deployed? Or maybe a previous destination or transformer step?
Reply With Quote
Old 11-05-2018, 02:19 AM
odo odo is offline
OBX.3 Kenobi
Join Date: Feb 2017
Location: Luxembourg
Posts: 139
odo is on a distinguished road

Either wrap your code with try/catch:
        globalChannelMap.put('pdf', FileUtil.encode(FileUtil.readBytes('/path/to/pdf')));
    } catch(ex){}
or (better) check first if there is a file:
     if(new java.io.File("/path/to/pdf").isFile()){
        globalChannelMap.put('pdf', FileUtil.encode(FileUtil.readBytes('/path/to/pdf')));
or (best) do both to ensure that the file is correctly read if present:
    if(new java.io.File("/path/to/pdf").isFile()){
            globalChannelMap.put('pdf', FileUtil.encode(FileUtil.readBytes('/path/to/pdf')));
            // treat reading errors here
Later, you can send the mail if the attribute is set:
        // send mail
The global channel map attributes are sustained between messages. If a pdf should be loaded for each message, the channelMap container must be used instead.
Reply With Quote

pdf attachment smtp

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 03:21 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation