Export (0) Print
Expand All

PrintQueue::AddJob Method (String)

Inserts a new print job, whose content is a Byte array, into the queue.

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

public:
PrintSystemJobInfo^ AddJob(
	String^ jobName
)

Parameters

jobName
Type: System::String

The name of the print job.

Return Value

Type: System.Printing::PrintSystemJobInfo
A PrintSystemJobInfo that represents the print job and its status.

Use this method to write device specific information, to a spool file, that is not automatically included by the Microsoft Windows spooler. Of course, you need to know whether the spool file is Enhanced Metafile (EMF) or XML Paper Specification (XPS). If you prefer to work with the Stream API, you can use the PrintQueueStream class instead of this method.

After the AddJob method has been called, you must write a Byte array to the JobStream property of the PrintSystemJobInfo that is returned by AddJob or no print job is created. This array is what prints if the printer is working and is not paused.

Caution noteCaution

If the JobStream is not closed with Close before the end of the thread in which AddJob is called, then an InvalidOperationException is thrown when that thread ends because the spooler thread cannot gain control over the Stream object.

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) to read a file into a Byte array and send the array to a print queue. This code assumes that there is a file called test.txt in the root of the C: drive. This code only works with printers that can detect and print plain text. Some of them cannot.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft