Page 1 of 1

Determine print job origination

Posted: Tue Dec 07, 2010 1:53 pm
by daniorg
Is it possible to determine where the print job originated from?

I want to only perform my custom logic when the "publish" button is pressed, not when printing normally.

Re: Determine print job origination

Posted: Tue Dec 07, 2010 5:07 pm
by Mark McKenna
When creating a print job handler, you can investigate the Properties of the IPrintJob object itself. There will be an entry keyed by Targets which provides the information you're looking for. Our default print job handlers all examine this value as they execute to selectively choose whether or not to actually do anything of interest (same thing you're trying to do).

For example:

Code: Select all

class MyPrintJobHandler : PrintJobHandler
{
	protected override PrintJobHandlerResult OnProcess( IPrintJob printJob )
	{
		// get the string that represents the enumeration value for the target we're interested in
		string publishTarget = Enum.GetName( typeof( PrintJobTarget ), PrintJobTarget.Publish );

		// see if the target we're interested in is one of the specified targets in the print job
		if ( ( printJob.Properties[PrintJobProperty.Targets] as List<String> ).Contains( publishTarget ) )
		{
			// do something
		}

		return PrintJobHandlerResult.Continue;
	}
}

Re: Determine print job origination

Posted: Tue Dec 07, 2010 5:22 pm
by daniorg
Just what I was looking for, thanks