Honestly your script looks fine, and I do more or less the same thing as you and it works well for me. The difference is that I look for specific document types and only email PDF's of those whereas I assume you will email a PDF for any document type.I can only assume that the creation of the rendition is causing the script to trigger over and over and the document type of the rendition is not cm
dfExport - it may well be cm:content in which case a PDF rendition and your original document will be indistingushable.One thing to try would be thisreplace
var renditionDef = renditionService.createRenditionDefinition('cm:'+document.name, 'reformat');
renditionDef.parameters['mime-type'] = "application/pdf";
var pdfFile = renditionService.render(document, renditionDef);
with
var pdfFile = document.transformDocument("application/pdf", userhome);
This will create the PDF document in userhome which (I presume) is not covered by your rule (if it is create the PDF somewhere that isn't).If that doesn't work I am at a loss, but please let me know as I will test it on my own installation and figure it out because this is important to me.