PrintQueue::AddJob Method (String^, String^, Boolean)

 

Inserts a new print job for an XML Paper Specification (XPS) Document into the queue, gives it the specified name, and specifies whether or not it should be validated.

Namespace:   System.Printing
Assembly:  System.Printing (in System.Printing.dll)

public:
PrintSystemJobInfo^ AddJob(
	String^ jobName,
	String^ documentPath,
	bool fastCopy
)

Parameters

jobName
Type: System::String^

The name of the print job.

documentPath
Type: System::String^

The path and name of the document that is being printed.

fastCopy
Type: System::Boolean

true to spool quickly without page-by-page progress feedback and without validating that the file is valid XPS; otherwise, false.

Return Value

Type: System.Printing::PrintSystemJobInfo^

A PrintSystemJobInfo that represents the print job and its status.

If fastCopy is true, then the printer must be an Printing Overview. If it is not, the AddJob(String^, String^, Boolean) method throws an exception.

If fastCopy is false, then it is not necessary to use an XPSDrv printer. The XPS file being added to the queue is converted to the printer's page description language, such as PCL or Postscript. However, this kind of printing makes a call to Component Object Model (COM). The call to COM requires that the calling thread have a single-threaded apartment (STA) instead of multiple-threaded apartment (MTA) which is the default in Microsoft .NET 2.0 and later. (For more on threading and apartment states, see Managed and Unmanaged Threading, and ApartmentState.) There are two ways of doing this: 

  • The simplest way is to add the STAThreadAttribute (that is, "[System.STAThreadAttribute()]") just above the first line of the application's Main method (usually "static void Main(string[] args)").

  • If you need your Main thread's apartment state to be MTA, you can house the call to AddJob(String^, String^, Boolean) in a separate thread whose apartment state is set to STA with SetApartmentState. The example below illustrates this second technique.

System_CAPS_noteNote

You cannot apply the STAThreadAttribute to any method except Main and you cannot use SetApartmentState for the Main thread.

Other ways to print in Windows Presentation Foundation (WPF) include the PrintDialog::PrintDocument method, which can be used with or without opening the dialog, and the many Write and WriteAsync methods of the XpsDocumentWriter.

The following example shows how to use AddJob(String^, String^, Boolean) to batch print all the XML Paper Specification (XPS) files in a directory.  

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.0
Return to top
Show: