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.

Testdoc

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.

  1. Rem -- This script will illustrate how to extract and process the text
  2. Rem -- of the printed output.
  3.  
  4. Sub OnConfigLoaded()
  5.     Rem -- Modify the configuration to extract text from the printer
  6.     Rem -- output.
  7.     Context("Config")("extracttext") = "yes"
  8. End Sub
  9.  
  10. Sub OnPreprocessText()
  11.     Const ForReading = 1
  12.     Dim fn, f, fso, cnt
  13.     Dim comment, p1, p2, l
  14.    
  15.     Rem -- Get the name of the text file from the context object
  16.     fn = Context("TextFileName")
  17.    
  18.     Rem -- Count the pages of the text file. Each page is separated
  19.     Rem -- by a formfeed character chr(12).
  20.     Set fso = CreateObject("Scripting.FilesystemObject")
  21.     Set f = fso.OpenTextFile(fn, ForReading)
  22.     While Not f.AtEndOfStream
  23.         Rem -- Read a line from the text file
  24.         l = f.ReadLine()
  25.  
  26.         Rem -- Look for the comment
  27.         p1 = InStr(1, l, "Kommentar:")
  28.         If p1 > 0 Then
  29.             comment = Mid(l, p1 + 8)
  30.  
  31.             Rem -- Look for the tag after the comment.
  32.             Rem -- This will determine where the comment ends.
  33.             p2 = InStr(1, comment, "Treibername:")
  34.             If p2 > 0 Then comment = Mid(comment, 1, p2 - 1)
  35.             comment = Trim(comment)
  36.         End If
  37.     Wend
  38.     f.Close
  39.  
  40.     Rem -- Set the author value in the configuration
  41.     Context("Config")("subject") = comment
  42. End Sub

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.

Downloads

Attachment Size
Example file 3.04 KB

Top