The PDF writer now features VBScript macros and event handlers. This means that you can now hook into the process of PDF creation by writing your own Visual Basic event handlers. You can also use Visual Basic Script in your macros for output file name, author, title, subject, and keyword properties.
VBScript events are an extremely strong tool for customizing the PDF writer for use in your own software. Writing the right event handlers gives you complete control over the PDF or image output and the dialogs shown to the user in the process. It enables you to bypass the normal dialogs and insert your own dialogs written in the programming language of your choice.
Program Life Cycle
In order to use the VBScript feature you must understand the program life cycle. The life cycle is a description of when an event is triggered and the information available to the event at that time in the process.
Event handlers often read and write information to a global Context variable. The global Context variable contains information about the current state of the document creation. Events can control the process by manipulating values in the Context variable.
The table below shows the order in which Event Handlers are triggered and Context Variables are set.
If an error is raised during the execution of a macro script then the document creation will abort and the error is reported. Errors can be caused by the executed code or raised explicitly by the programmer.
The example code below shows how you can raise an error.