After creating a PDF file, the PDF Printer can be set up so that it automatically sends this PDF file with Outlook, an Exchange server or via an IMAP server via email. We want to show you how this works here. For this we use the built-in VBScript event handler of our printer and the MAPI Api to address Outlook. As an example, you can also coordinate an Exchange Server or an IMAP Server (see download example at the bottom), as mentioned by adjusting a few lines of code! The example shown is intended to support you in realizing this automation.

Please note that this example requires licensing of the Professional Edition, i.e. a license.xml file Professional, because the Event Handler can only be used from the Professional Edition.

In our example, we configure our PDF printer in the tab "E-Mail" in the Options dialog window, and we already give the PDF printer the recipient's email address, subject and body text. For breaks in body text, we use HTML code and the well-known <br> HTML Tag. Instead of specifying this information fix, you could also read it dynamically from the Active Directory via VBScript and LDAP. This is also possible with a few lines of code. Basically, you can tap into any data source and then integrate it into the process in the VBScript coding, which is listed below, and thus act even more flexibly. For our example, we will limit ourselves to a fixed configuration that is stored in the PDF printer.

Fixed configuration mail dispatch in the options dialog of the PDF printer
Illustration: Fixed mail configuration of recipient, subject and text.

Next we come to the event handler of the PDF printer. We can tap this using a small macro script in VBScript. We put the macro in the Macros folder of the PDF printer. This is always in the installation path of the PDF printer. So mostly under:

C:\Program Files\7-PDF\PDF Printer\Macros

Macros directory of the PDF printer for addressing the event handler
Illustration: We save the VBScript code in the Macros folder as mapi.vbs

We come to the actual code of our example, which we have saved in the Macros directory in the VBS file mapi.vbs as shown in the screenshot above.

Dim global_success

Sub OnSuccess()
	global_success = true
End Sub

Sub OnAfterPrint()
	If global_success Then
		Rem -- Get the file name from the command line
		fn = Context("OutputFileName")

		Rem -- Get access to the Outlook application
		Set ol = CreateObject("Outlook.Application")
		Set ns = ol.getNamespace("MAPI")

		Rem -- Create the new mail
		Set newMail = ol.CreateItem(olMailItem)

		Rem -- Build eMail and attach the pdf file
		newMail.To = Context("Config")("emailto")
		newMail.Subject = Context("OutputFileName") + " " + Context("Config")("emailsubject")
		newMail.HTMLBody = Context("Config")("emailbody")
		newMail.Attachments.Add fn

		Rem -- Display the new message
		Rem --  Del PDF
		Rem -- Set objFSO = CreateObject("Scripting.FileSystemObject")
		Rem -- objFSO.DeleteFile(Context("OutputFileName"))
		MsgBox "An error has occurred. Please try again!"
	End If

End Sub

What does the script do? In the coding we see two events of the PDF printer, OnSuccess() and OnAfterPrint(). If PDF creation is successful, a global variable global_success is set to TRUE in OnSuccess ().

This is reacted to in OnAfterPrint() and, if successful, the MAPI from Outlook is addressed. From the configuration of the PDF printer, the fixed mail recipient, subject and body text are determined and the MAPI is filled by Outlook. As an attachment, the file handle fn is placed on the PDF file previously created by the PDF printer and attached to the email. Finally, the email is automatically called up in Outlook. Instead of newMail.Display one could have carried out the automatic sending with newMail.Send. The commented out lower lines of VBScript code would delete the PDF file previously created by the PDF printer.

As already mentioned, the example shown above should only provide an introduction for you and illustrate the possibilities of our PDF printer. With a few lines of code, you can use the PDF printer most effectively and automate many processes related to PDF generation. And you don't need any additional tools, just our PDF printer.

Example file download

You can download the sample code ( here. Furthermore, we have provided an example ( for download, which shows how you can use the Gmail IMAP server to send PDF files instead of Outlook. Make sure that you copy the VBS file that suits you into the Macros folder of the PDF printer as shown above!

LiveZilla Live Chat Software