PrintQueue.AddJob 메서드

정의

큐에 새 인쇄 작업을 삽입합니다.

오버로드

AddJob(String, String, Boolean, PrintTicket)

XPS(XML Paper Specification) 문서에 대한 새 인쇄 작업을 큐에 삽입하고, 지정한 이름과 설정을 제공하고, 유효성을 검사해야 하는지 여부를 지정합니다.

AddJob(String, PrintTicket)

XPS(XML Paper Specification) 문서의 새 인쇄 작업을 큐에 삽입하고 지정된 이름과 설정을 지정합니다.

AddJob(String, String, Boolean)

XPS(XML Paper Specification) 문서의 새 인쇄 작업을 큐에 삽입하고 지정된 이름을 지정하며 유효성을 검사해야 하는지 여부를 지정합니다.

AddJob()

콘텐츠가 Byte 배열인 새로운 인쇄 작업(일반적으로 이름이 지정됨)을 큐에 삽입합니다.

AddJob(String)

콘텐츠가 Byte 배열인 새 인쇄 작업을 큐에 삽입합니다.

설명

큐가 일시 중지되거나 오류 상태가 아니면 작업이 큐의 맨 위에 도달하면 인쇄되므로 인쇄 함수입니다.

WPF(Windows Presentation Foundation)에서 인쇄하는 다른 방법에는 대화 상자를 열거나 열지 않고 사용할 수 있는 메서드와 의 여러 WriteWriteAsync 메서드가 XpsDocumentWriter포함 PrintDialog.PrintDocument 됩니다.

AddJob(String, String, Boolean, PrintTicket)

XPS(XML Paper Specification) 문서에 대한 새 인쇄 작업을 큐에 삽입하고, 지정한 이름과 설정을 제공하고, 유효성을 검사해야 하는지 여부를 지정합니다.

public:
 System::Printing::PrintSystemJobInfo ^ AddJob(System::String ^ jobName, System::String ^ documentPath, bool fastCopy, System::Printing::PrintTicket ^ printTicket);
public System.Printing.PrintSystemJobInfo AddJob (string jobName, string documentPath, bool fastCopy, System.Printing.PrintTicket printTicket);
member this.AddJob : string * string * bool * System.Printing.PrintTicket -> System.Printing.PrintSystemJobInfo
Public Function AddJob (jobName As String, documentPath As String, fastCopy As Boolean, printTicket As PrintTicket) As PrintSystemJobInfo

매개 변수

jobName
String

인쇄하고 있는 문서의 경로와 이름입니다.

documentPath
String

인쇄하고 있는 문서의 경로와 이름입니다.

fastCopy
Boolean

true 페이지별 진행률 피드백 없이 파일이 유효한 XPS인지 확인하지 않고 신속하게 스풀링합니다. 그렇지 않으면 입니다 false.

printTicket
PrintTicket

인쇄 작업의 설정입니다.

반환

인쇄 작업 및 그 상태를 나타내는 PrintSystemJobInfo입니다.

설명

자세한 내용은 AddJob(String, String, Boolean)를 참조하세요.

적용 대상

AddJob(String, PrintTicket)

XPS(XML Paper Specification) 문서의 새 인쇄 작업을 큐에 삽입하고 지정된 이름과 설정을 지정합니다.

public:
 System::Printing::PrintSystemJobInfo ^ AddJob(System::String ^ jobName, System::Printing::PrintTicket ^ printTicket);
public System.Printing.PrintSystemJobInfo AddJob (string jobName, System.Printing.PrintTicket printTicket);
member this.AddJob : string * System.Printing.PrintTicket -> System.Printing.PrintSystemJobInfo
Public Function AddJob (jobName As String, printTicket As PrintTicket) As PrintSystemJobInfo

매개 변수

jobName
String

인쇄하고 있는 문서의 경로와 이름입니다.

printTicket
PrintTicket

인쇄 작업의 설정입니다.

반환

인쇄 작업 및 그 상태를 나타내는 PrintSystemJobInfo입니다.

설명

자세한 내용은 AddJob(String)를 참조하세요.

적용 대상

AddJob(String, String, Boolean)

XPS(XML Paper Specification) 문서의 새 인쇄 작업을 큐에 삽입하고 지정된 이름을 지정하며 유효성을 검사해야 하는지 여부를 지정합니다.

public:
 System::Printing::PrintSystemJobInfo ^ AddJob(System::String ^ jobName, System::String ^ documentPath, bool fastCopy);
public System.Printing.PrintSystemJobInfo AddJob (string jobName, string documentPath, bool fastCopy);
member this.AddJob : string * string * bool -> System.Printing.PrintSystemJobInfo
Public Function AddJob (jobName As String, documentPath As String, fastCopy As Boolean) As PrintSystemJobInfo

매개 변수

jobName
String

인쇄 작업의 이름입니다.

documentPath
String

인쇄하고 있는 문서의 경로와 이름입니다.

fastCopy
Boolean

true 페이지별 진행률 피드백 없이 파일이 유효한 XPS인지 확인하지 않고 신속하게 스풀링합니다. 그렇지 않으면 입니다 false.

반환

인쇄 작업 및 그 상태를 나타내는 PrintSystemJobInfo입니다.

예제

다음 예제에서는 를 사용하여 AddJob(String, String, Boolean) 디렉터리의 모든 XPS(XML Paper Specification) 파일을 일괄 인쇄하는 방법을 보여 줍니다.

class Program
{
    [System.MTAThreadAttribute()] // Added for clarity, but this line is redundant because MTA is the default.
    static void Main(string[] args)
    {
        // Create the secondary thread and pass the printing method for 
        // the constructor's ThreadStart delegate parameter. The BatchXPSPrinter
        // class is defined below.
        Thread printingThread = new Thread(BatchXPSPrinter.PrintXPS);

        // Set the thread that will use PrintQueue.AddJob to single threading.
        printingThread.SetApartmentState(ApartmentState.STA);

        // Start the printing thread. The method passed to the Thread 
        // constructor will execute.
        printingThread.Start();
    }
}

public class BatchXPSPrinter
{
    public static void PrintXPS()
    {
        // Create print server and print queue.
        LocalPrintServer localPrintServer = new LocalPrintServer();
        PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();

        // Prompt user to identify the directory, and then create the directory object.
        Console.Write("Enter the directory containing the XPS files: ");
        String directoryPath = Console.ReadLine();
        DirectoryInfo dir = new DirectoryInfo(directoryPath);

        // If the user mistyped, end the thread and return to the Main thread.
        if (!dir.Exists)
        {
            Console.WriteLine("There is no such directory.");
        }
        else
        {
            // If there are no XPS files in the directory, end the thread 
            // and return to the Main thread.
            if (dir.GetFiles("*.xps").Length == 0)
            {
                Console.WriteLine("There are no XPS files in the directory.");
            }
            else
            {
                Console.WriteLine("\nJobs will now be added to the print queue.");
                Console.WriteLine("If the queue is not paused and the printer is working, jobs will begin printing.");

                // Batch process all XPS files in the directory.
                foreach (FileInfo f in dir.GetFiles("*.xps"))
                {
                    String nextFile = directoryPath + "\\" + f.Name;
                    Console.WriteLine("Adding {0} to queue.", nextFile);

                    try
                    {
                        // Print the Xps file while providing XPS validation and progress notifications.
                        PrintSystemJobInfo xpsPrintJob = defaultPrintQueue.AddJob(f.Name, nextFile, false);
                    }
                    catch (PrintJobException e)
                    {
                        Console.WriteLine("\n\t{0} could not be added to the print queue.", f.Name);
                        if (e.InnerException.Message == "File contains corrupted data.")
                        {
                            Console.WriteLine("\tIt is not a valid XPS file. Use the isXPS Conformance Tool to debug it.");
                        }
                        Console.WriteLine("\tContinuing with next XPS file.\n");
                    }
                }
            }
        }

        Console.WriteLine("Press Enter to end program.");
        Console.ReadLine();
    }
}
Friend Class Program
    <System.MTAThreadAttribute()>
    Shared Sub Main(ByVal args() As String) ' Added for clarity, but this line is redundant because MTA is the default.
        ' Create the secondary thread and pass the printing method for 
        ' the constructor's ThreadStart delegate parameter. The BatchXPSPrinter
        ' class is defined below.
        Dim printingThread As New Thread(AddressOf BatchXPSPrinter.PrintXPS)

        ' Set the thread that will use PrintQueue.AddJob to single threading.
        printingThread.SetApartmentState(ApartmentState.STA)

        ' Start the printing thread. The method passed to the Thread 
        ' constructor will execute.
        printingThread.Start()

    End Sub

End Class

Public Class BatchXPSPrinter
    Public Shared Sub PrintXPS()
        ' Create print server and print queue.
        Dim localPrintServer As New LocalPrintServer()
        Dim defaultPrintQueue As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()

        ' Prompt user to identify the directory, and then create the directory object.
        Console.Write("Enter the directory containing the XPS files: ")
        Dim directoryPath As String = Console.ReadLine()
        Dim dir As New DirectoryInfo(directoryPath)

        ' If the user mistyped, end the thread and return to the Main thread.
        If Not dir.Exists Then
            Console.WriteLine("There is no such directory.")
        Else
            ' If there are no XPS files in the directory, end the thread 
            ' and return to the Main thread.
            If dir.GetFiles("*.xps").Length = 0 Then
                Console.WriteLine("There are no XPS files in the directory.")
            Else
                Console.WriteLine(vbLf & "Jobs will now be added to the print queue.")
                Console.WriteLine("If the queue is not paused and the printer is working, jobs will begin printing.")

                ' Batch process all XPS files in the directory.
                For Each f As FileInfo In dir.GetFiles("*.xps")
                    Dim nextFile As String = directoryPath & "\" & f.Name
                    Console.WriteLine("Adding {0} to queue.", nextFile)

                    Try
                        ' Print the Xps file while providing XPS validation and progress notifications.
                        Dim xpsPrintJob As PrintSystemJobInfo = defaultPrintQueue.AddJob(f.Name, nextFile, False)
                    Catch e As PrintJobException
                        Console.WriteLine(vbLf & vbTab & "{0} could not be added to the print queue.", f.Name)
                        If e.InnerException.Message = "File contains corrupted data." Then
                            Console.WriteLine(vbTab & "It is not a valid XPS file. Use the isXPS Conformance Tool to debug it.")
                        End If
                        Console.WriteLine(vbTab & "Continuing with next XPS file." & vbLf)
                    End Try

                Next f ' end for each XPS file

            End If 'end if there are no XPS files in the directory

        End If 'end if the directory does not exist

        Console.WriteLine("Press Enter to end program.")
        Console.ReadLine()

    End Sub

End Class

설명

가 이truefastCopy 프린터는 인쇄 개요여야 합니다. 그렇지 않으면 메서드가 AddJob(String, String, Boolean) 예외를 throw합니다.

가 이falsefastCopy XPSDrv 프린터를 사용할 필요가 없습니다. 큐에 추가되는 XPS 파일은 PCL 또는 Postscript와 같은 프린터의 페이지 설명 언어로 변환됩니다. 그러나 이러한 종류의 인쇄는 COM(구성 요소 개체 모델)을 호출합니다. COM을 호출하려면 호출 스레드에 Microsoft .NET 2.0 이상의 기본값인 다중 스레드 아파트() 대신 단일 스레드 아파트STA(MTA)가 있어야 합니다. (스레딩 및 아파트 상태에 대한 자세한 내용은 관리 및 관리되지 않는 스레딩 및ApartmentState 를 참조하세요.) 이 작업을 수행하는 방법에는 두 가지가 있습니다.

  • 가장 간단한 방법은 추가 하는 것은 STAThreadAttribute (즉, "[System.STAThreadAttribute()]") 애플리케이션의 첫 번째 줄 바로 위에 Main 메서드 (일반적으로 "static void Main(string[] args)").

  • 스레드의 아파트 상태가 이어야 MTA하는 경우 Main 을 사용하여 아파트 상태가 로 설정된 별도의 스레드에 호출 AddJob(String, String, Boolean)STASetApartmentState저장할 수 있습니다. 아래 예제에서는 이 두 번째 기술을 보여 줍니다.

참고

를 제외한 Main 모든 메서드에 를 STAThreadAttribute 적용할 수 없으며 스레드에 를 Main 사용할 SetApartmentState 수 없습니다.

WPF(Windows Presentation Foundation)에서 인쇄하는 다른 방법에는 대화 상자를 열거나 열지 않고 사용할 수 있는 메서드와 의 여러 WriteWriteAsync 메서드가 XpsDocumentWriter포함 PrintDialog.PrintDocument 됩니다.

추가 정보

적용 대상

AddJob()

콘텐츠가 Byte 배열인 새로운 인쇄 작업(일반적으로 이름이 지정됨)을 큐에 삽입합니다.

public:
 System::Printing::PrintSystemJobInfo ^ AddJob();
public System.Printing.PrintSystemJobInfo AddJob ();
member this.AddJob : unit -> System.Printing.PrintSystemJobInfo
Public Function AddJob () As PrintSystemJobInfo

반환

인쇄 작업 및 그 상태를 나타내는 PrintSystemJobInfo입니다.

예제

다음 예제에서는 를 사용하여 AddJob() 배열을 Byte 인쇄 큐로 보내는 방법을 보여 드립니다. 이 코드는 일반 텍스트를 감지하고 인쇄할 수 있는 프린터에서만 작동합니다. 그들 중 일부는 할 수 없습니다.

// Create the printer server and print queue objects
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();

// Call AddJob
PrintSystemJobInfo myPrintJob = defaultPrintQueue.AddJob();

// Write a Byte buffer to the JobStream and close the stream
Stream myStream = myPrintJob.JobStream;
Byte[] myByteBuffer = UnicodeEncoding.Unicode.GetBytes("This is a test string for the print job stream.");
myStream.Write(myByteBuffer, 0, myByteBuffer.Length);
myStream.Close();
' Create the printer server and print queue objects
Dim localPrintServer As New LocalPrintServer()
Dim defaultPrintQueue As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()

' Call AddJob
Dim myPrintJob As PrintSystemJobInfo = defaultPrintQueue.AddJob()

' Write a Byte buffer to the JobStream and close the stream
Dim myStream As Stream = myPrintJob.JobStream
Dim myByteBuffer() As Byte = UnicodeEncoding.Unicode.GetBytes("This is a test string for the print job stream.")
myStream.Write(myByteBuffer, 0, myByteBuffer.Length)
myStream.Close()

설명

이 메서드를 사용하여 Microsoft Windows 스풀러에 의해 자동으로 포함되지 않는 스풀 파일에 디바이스 관련 정보를 작성합니다. 물론 스풀 파일이 EMF(Enhanced Metafile) 또는 XPS(XML Paper Specification)인지 알아야 합니다. API를 Stream 사용하려는 경우 이 메서드 대신 클래스를 PrintQueueStream 사용할 수 있습니다.

메서드가 AddJob 호출된 후에는 에 의해 반환되거나 인쇄 작업이 만들어지지 않은 의 PrintSystemJobInfo 속성에 AddJob 배열 JobStream 을 작성 Byte 해야 합니다. 이 배열은 프린터가 작동하고 일시 중지되지 않은 경우 인쇄됩니다.

주의

JobStream 가 호출 InvalidOperationException 되는 AddJob 스레드의 끝 전에 를 로 Close 닫지 않으면 스풀러 스레드가 개체를 Stream 제어할 수 없기 때문에 해당 스레드가 종료될 때 이 throw됩니다.

인쇄 큐의 GUI(그래픽 사용자 인터페이스)에서 작업에는 "인쇄 시스템 문서"라는 이름이 있습니다. 작업에 다른 이름을 지정하려면 오버로드를 AddJob(String) 사용합니다.

WPF(Windows Presentation Foundation)에서 인쇄하는 다른 방법에는 대화 상자를 열거나 열지 않고 사용할 수 있는 메서드와 의 여러 WriteWriteAsync 메서드가 XpsDocumentWriter포함 PrintDialog.PrintDocument 됩니다.

적용 대상

AddJob(String)

콘텐츠가 Byte 배열인 새 인쇄 작업을 큐에 삽입합니다.

public:
 System::Printing::PrintSystemJobInfo ^ AddJob(System::String ^ jobName);
public System.Printing.PrintSystemJobInfo AddJob (string jobName);
member this.AddJob : string -> System.Printing.PrintSystemJobInfo
Public Function AddJob (jobName As String) As PrintSystemJobInfo

매개 변수

jobName
String

인쇄 작업의 이름입니다.

반환

인쇄 작업 및 그 상태를 나타내는 PrintSystemJobInfo입니다.

예제

다음 예제에서는 를 사용하여 AddJob(String) 파일을 배열로 읽고 배열을 Byte 인쇄 큐로 보내는 방법을 보여 드립니다. 이 코드는 C: 드라이브의 루트에 test.txt 라는 파일이 있다고 가정합니다. 이 코드는 일반 텍스트를 감지하고 인쇄할 수 있는 프린터에서만 작동합니다. 그들 중 일부는 할 수 없습니다.

// Create the printer server and print queue objects
LocalPrintServer localPrintServer2 = new LocalPrintServer();
PrintQueue defaultPrintQueue2 = LocalPrintServer.GetDefaultPrintQueue();

// Call AddJob 
PrintSystemJobInfo anotherPrintJob = defaultPrintQueue2.AddJob("MyJob");

// Read a file into a StreamReader
StreamReader myStreamReader = new StreamReader("C:\\test.txt");

// Write a Byte buffer to the JobStream and close the stream
Stream anotherStream = anotherPrintJob.JobStream;
Byte[] anotherByteBuffer = UnicodeEncoding.Unicode.GetBytes(myStreamReader.ReadToEnd());
anotherStream.Write(anotherByteBuffer, 0, anotherByteBuffer.Length);
anotherStream.Close();
' Create the printer server and print queue objects
Dim localPrintServer2 As New LocalPrintServer()
Dim defaultPrintQueue2 As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()

' Call AddJob 
Dim anotherPrintJob As PrintSystemJobInfo = defaultPrintQueue2.AddJob("MyJob")

' Read a file into a StreamReader
Dim myStreamReader As New StreamReader("C:\test.txt")

' Write a Byte buffer to the JobStream and close the stream
Dim anotherStream As Stream = anotherPrintJob.JobStream
Dim anotherByteBuffer() As Byte = UnicodeEncoding.Unicode.GetBytes(myStreamReader.ReadToEnd())
anotherStream.Write(anotherByteBuffer, 0, anotherByteBuffer.Length)
anotherStream.Close()

설명

이 메서드를 사용하여 Microsoft Windows 스풀러에 의해 자동으로 포함되지 않는 스풀 파일에 디바이스 관련 정보를 작성합니다. 물론 스풀 파일이 EMF(Enhanced Metafile) 또는 XPS(XML Paper Specification)인지 알아야 합니다. API를 Stream 사용하려는 경우 이 메서드 대신 클래스를 PrintQueueStream 사용할 수 있습니다.

메서드가 AddJob 호출된 후에는 에 의해 반환되거나 인쇄 작업이 만들어지지 않은 의 PrintSystemJobInfo 속성에 AddJob 배열 JobStream 을 작성 Byte 해야 합니다. 이 배열은 프린터가 작동하고 일시 중지되지 않은 경우 인쇄됩니다.

주의

JobStream 가 호출 InvalidOperationException 되는 AddJob 스레드의 끝 전에 를 로 Close 닫지 않으면 스풀러 스레드가 개체를 Stream 제어할 수 없기 때문에 해당 스레드가 종료될 때 이 throw됩니다.

WPF(Windows Presentation Foundation)에서 인쇄하는 다른 방법에는 대화 상자를 열거나 열지 않고 사용할 수 있는 메서드와 의 여러 WriteWriteAsync 메서드가 XpsDocumentWriter포함 PrintDialog.PrintDocument 됩니다.

적용 대상