Extracting Usernames in Enterprise Print Environments (e.g. SAP, Unix)

It is common in an enterprise print environment using packages such as SAP, JD Edwards, Oracle Financials or Unix systems for print jobs (e.g. batch reports) to appear in print queues under a system account name rather than the instigating user’s account name. The result is that all jobs printed from these programs are recorded in the PaperCut NG job log as owned by the program/system account.

In most environments, these programs or systems can be configured to write the username into the print spool file (PDL). For example, the username may be added as a PJL header. If this is done then PaperCut can extract the username and use it in place of the username supplied to the print queue.

Tip

This feature is often combined with Username Aliases (see [app-path]/server/data/conf/username-aliases.txt) when dealing with differences between the usernames used in the PaperCut NG environment and the external system or program that submits these jobs. For example, john.wayne in PaperCut NG may have jwayne as a SAP user ID.

The extraction process, when configured, follows a number of rules that an administrator should be aware of:

  1. It is possible to define multiple patterns to extract the username. The matching process will return the first valid result found.

  2. Username extraction at the current time applies only to Windows print queues.

  3. The username should appear in the first megabyte of the spool file.

Configuring PaperCut to Extract Usernames from Spool Files

Username extraction from spool files is performed by the PaperCut Print Provider and as such any configuration text described in the following steps needs to be inserted into [app_path]\providers\print\win\print-provider.conf. After a change to the config is made, the Print Provider service should be restart before testing.

Extracting Usernames using the Simple Method

The Simple Method uses prefix and suffix text as static bookends for the username that should be extracted. In the below example (which can be copied and pasted into your print-provider.conf), the user john.wayne will be extracted from the string @PJL COMMENT SAP_USER="john.wayne". Simple Matching should be sufficient in the majority of customer environments.

#
# Extract username from spool files coming from our enterprise system.
# Look for a header that matches @PJL COMMENT SAP_USER="john.wayne"
#
UsernameOverridePrefix=@PJL COMMENT SAP_USER="  
UsernameOverrideSuffix="
                    

Extracting Usernames using the Advanced Method (Regular Expressions)

The Advanced method adds powerful regular expression pattern plus the ability to define up to five of these patterns, labelled UsernameOverrideRegex1 to UsernameOverrideRegex5. Administrators using this method should be familiar with regular expressions. The username is extracted from the first bracketed match group (e.g. $1).

In the example below two patterns are matched:

#
# Extract username from spool files coming from our enterprise system.
# Username may be defined in one of two formats:
#   (john.wayne) XJXsetUserName
#   /Author (john.wayne) def
#
UsernameOverrideRegex1=\((\S+?)\)\s*XJXsetUserName
UsernameOverrideRegex2=Author\s*\((\S+?)\)\s*def
                    

The table below shows some further examples of username declarations seen in spool files and corresponding regular expressions that can extract the correct username.

Username in Spool FileRegular Expression to Extract Username
@PJL SET USERNAME="john.wayne"@PJL\s+SET\s+USERNAME\s*=\s*"(\S+?)"
@PJL SET USERNAMEW="john.wayne"@PJL\s+SET\s+USERNAMEW\s*=\s*"(\S+?)"
@PJL XJAUSERNAME = "john.wayne"@PJL\s+XJAUSERNAME\s*=\s*"(\S+?)"
@PJL COMMENT "Username: john.wayne"@PJL\s+COMMENT\s+"Username\s*:\s*(\S+?)"
@PJL COMMENT CANPJL SET USERNAME="john.wayne"@PJL\s+COMMENT\s+CANPJL\s+SET\s+USERNAME\s*=\s*"(\S+?)"
@PJL COMMENT "Username: john.wayne;App FileName: True Grit.doc"@PJL\s+COMMENT\s*"Username\s*:\s*(\S+?)\s*;
@PJL OKIAUXJOBINFO DATA="UserName=john.wayne"@PJL\s+OKIAUXJOBINFO\s+DATA\s*=\s*"UserName\s*=\s*(\S+?)\s*"
%%For: john.wayne%%For:\s*\(?([\w\.-=]+?)\)?\b
/USERNAME (john.wayne) def/USERNAME\s*\((\S+?)\)\s*def
/UserName (john.wayne) def/UserName\s*\((\S+?)\)\s*def
/Author (john.wayne) def/Author\s*\((\S+?)\)\s*def
(john.wayne) /RRCustomProcs /ProcSet findresource begin logusername end\((\S+?)\)\s*/RRCustomProcs\s*/ProcSet\s+findresource\s+begin\s+logusername
(john.wayne) XJXsetUserName\((\S+?)\)\s*XJXsetUserName

Table 7.5. Examples of usernames seen in spool files and regular expressions to extract them