// TestPage2JPG.js script // Part of PDFCreator // License: GPL // Homepage: http://www.pdfforge.org/pdfcreator // Windows Scripting Host version: 5.6 // Version: 1.0.0.0 // Date: July, 28. 2014 // Author: Sazan Hoti // Comments: This script demonstrates the conversion of a printable user chosen file in a tif-file under "DefaultGuid" profile using // the COM interface of PDFCreator and eventually sending the converted file via SMTP. var maxTimeOut = 5 // in seconds var objFSO = new ActiveXObject("Scripting.FileSystemObject"); var objShell = new ActiveXObject("Shell.Application"); var Scriptname = objFSO.GetFileName(WScript.ScriptFullname); /* The following variables are used for the e-mail SMTP settings. If you execute this script with the given variable content then you will get an alert saying that the converted file could not be send. */ var address = "test@pdfforge.org"; var recipients = "test@pdfforge.org"; var port = "25"; var username = "user"; var password = "abc"; var server = "mymail.server.org"; var subject = "test"; if (WScript.Version < 5.6) { WScript.Echo("You need the \"Windows Scripting Host version 5.6\" or greater!"); WScript.Quit(); } try { var PDFCreatorQueue = new ActiveXObject("PDFCreatorBeta.JobQueue"); WScript.Echo("Initializing PDFCreator queue..."); PDFCreatorQueue.Initialize(); var fullPath = objFSO.GetParentFolderName(WScript.ScriptFullname) + "\\" + "Testpage.pdf"; WScript.Echo("Setting up target path to: " + fullPath); WScript.Echo("Printing one windows test page..."); objShell.ShellExecute("RUNDLL32.exe", "PRINTUI.DLL,PrintUIEntry /k /n \"PDFCreator\"", "", "open", 1); WScript.Echo("Waiting for the job to arrive at the queue for " + maxTimeOut + " seconds"); if(!PDFCreatorQueue.WaitForJob(maxTimeOut)) { WScript.Echo("The print job did not reach the queue within " + maxTimeOut + " seconds"); } else { WScript.Echo("Currently there are " + PDFCreatorQueue.Count + " job(s) in the queue"); WScript.Echo("Getting job instance"); var job = PDFCreatorQueue.NextJob; job.SetProfileByGuid("DefaultGuid"); /* The SetProfileSettings method allows us to tell the job that it should be send after conversion via SMTP without further interaction */ //Since we want to send the converted file, we have to enable the EmailSmtp action job.SetProfileSetting("EmailSmtp.Enabled","true"); //Setting up the address that should be displayed as sender job.SetProfileSetting("EmailSmtp.Address", address); //Setting up the recipients job.SetProfileSetting("EmailSmtp.Recipients",recipients); //Setting up the SMTP server port job.SetProfileSetting("EmailSmtp.Port",port); //User name for authentication at server job.SetProfileSetting("EmailSmtp.UserName",username); //Password for authentication at server job.SetProfileSetting("EmailSmtp.Password",password); //Setting up host name of the e-mail server job.SetProfileSetting("EmailSmtp.Server",server); //Setting up the subject of the mail job.SetProfileSetting("EmailSmtp.Subject",subject); //Get the guid of the used profile var guid = job.GetProfileSetting("Guid"); WScript.Echo("Converting under " + guid + " conversion profile"); job.ConvertTo(fullPath); if(!job.IsFinished || !job.IsSuccessful) { WScript.Echo("Converted file could not be send. This is because we used non existing E-Mail accounts."); } else { WScript.Echo("Job finished successfully"); } } WScript.Echo("Releasing the COM object"); PDFCreatorQueue.ReleaseCom(); } catch(e) { WScript.Echo(e.message); //Emptying the queue if an exception occurred PDFCreatorQueue.ReleaseCom(); }