Parse Input Using OnPreprocessText Event Handler
This example will show you how to extract information from the print job and use it to set
the document subject.
A sample document is included for use in this example. It contains a comment,
which we would like to extract and use as the PDF subject.
The image below shows the sample document with the highlighted comment.
When the document is printed we use an event handler for the OnPreprocessText event
to parse the text representation of the print job.
Below you will find the implementation of the event handler.
Rem -- This script will illustrate how to extract and process the text
Rem -- of the printed output.
Rem -- Modify the configuration to extract text from the printer
Rem -- output.
Context("Config")("extracttext") = "yes"
Const ForReading = 1
Dim fn, f, fso, cnt
Dim comment, p1, p2, l
Rem -- Get the name of the text file from the context object
fn = Context("TextFileName")
Rem -- Count the pages of the text file. Each page is separated
Rem -- by a formfeed character chr(12).
Set fso = CreateObject("Scripting.FilesystemObject")
Set f = fso.OpenTextFile(fn, ForReading)
While Not f.AtEndOfStream
Rem -- Read a line from the text file
l = f.ReadLine()
Rem -- Look for the comment
p1 = InStr(1, l, "Comment:")
If p1 > 0 Then
comment = Mid(l, p1 + 8)
Rem -- Look for the tag after the comment.
Rem -- This will determine where the comment ends.
p2 = InStr(1, comment, "Driver name:")
If p2 > 0 Then comment = Mid(comment, 1, p2 - 1)
comment = Trim(comment)
Rem -- Set the author value in the configuration
Context("Config")("subject") = comment
Download Example Files
You can download and run the example yourself. The files needed are available here.
The VBS file must be placed in the
macros sub folder of the PDF writer installation.
You can use the MacroDir setting to change the location of the VBS files if needed.
Example files (zip archive)