Sdílet prostřednictvím


PrintQueue.AddJob Metoda

Definice

Vloží do fronty novou tiskovou úlohu.

Přetížení

Name Description
AddJob(String, String, Boolean, PrintTicket)

Vloží do fronty novou tiskovou úlohu dokumentu XPS (XML Paper Specification), poskytne jí zadaný název a nastavení a určuje, zda má být ověřen.

AddJob(String, PrintTicket)

Vloží do fronty novou tiskovou úlohu dokumentu XPS (XML Paper Specification) a poskytne jí zadaný název a nastavení.

AddJob(String, String, Boolean)

Vloží do fronty novou tiskovou úlohu dokumentu XPS (XML Paper Specification), zadá zadaný název a určí, zda má být ověřen.

AddJob()

Vloží do fronty novou (obecně pojmenovanou Byte ) tiskovou úlohu, jejíž obsah je pole.

AddJob(String)

Vloží novou tiskovou úlohu, jejíž obsah je Byte pole, do fronty.

Poznámky

Pokud není fronta pozastavená nebo je v chybovém stavu, úloha se vytiskne, když dosáhne horní části fronty, takže se jedná o tiskovou funkci.

Další způsoby tisku ve Windows Presentation Foundation (WPF) zahrnují metoduPrintDialog.PrintDocument, kterou lze použít s dialogovým oknem nebo bez otevření dialogového XpsDocumentWriterokna a mnoho Write a WriteAsync metod .

AddJob(String, String, Boolean, PrintTicket)

Vloží do fronty novou tiskovou úlohu dokumentu XPS (XML Paper Specification), poskytne jí zadaný název a nastavení a určuje, zda má být ověřen.

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

Parametry

jobName
String

Cesta a název tištěného dokumentu.

documentPath
String

Cesta a název tištěného dokumentu.

fastCopy
Boolean

truerychlé zařazování bez zpětné vazby o průběhu stránky a bez ověření, že soubor je platný XPS; v opačném případě . false

printTicket
PrintTicket

Nastavení tiskové úlohy.

Návraty

A PrintSystemJobInfo , který představuje tiskovou úlohu a její stav.

Poznámky

Další informace najdete na webu AddJob(String, String, Boolean).

Platí pro

AddJob(String, PrintTicket)

Vloží do fronty novou tiskovou úlohu dokumentu XPS (XML Paper Specification) a poskytne jí zadaný název a nastavení.

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

Parametry

jobName
String

Cesta a název tištěného dokumentu.

printTicket
PrintTicket

Nastavení tiskové úlohy.

Návraty

A PrintSystemJobInfo , který představuje tiskovou úlohu a její stav.

Poznámky

Další informace najdete na webu AddJob(String).

Platí pro

AddJob(String, String, Boolean)

Vloží do fronty novou tiskovou úlohu dokumentu XPS (XML Paper Specification), zadá zadaný název a určí, zda má být ověřen.

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

Parametry

jobName
String

Název tiskové úlohy.

documentPath
String

Cesta a název tištěného dokumentu.

fastCopy
Boolean

truerychlé zařazování bez zpětné vazby o průběhu stránky a bez ověření, že soubor je platný XPS; v opačném případě . false

Návraty

A PrintSystemJobInfo , který představuje tiskovou úlohu a její stav.

Příklady

Následující příklad ukazuje, jak použít AddJob(String, String, Boolean) k dávkovému tisku všech souborů XML Paper Specification (XPS) v adresáři.

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

Poznámky

Pokud fastCopy ano true, musí být tiskárna přehledem tisku. Pokud tomu tak není, AddJob(String, String, Boolean) vyvolá metoda výjimku.

Pokud fastCopy je false, není nutné použít tiskárnu XPSDrv. Soubor XPS přidaný do fronty se převede do jazyka popisu stránky tiskárny, jako je PCL nebo Postscript. Tento typ tisku však volá model COM (Component Object Model). Volání modelu COM vyžaduje, aby volající vlákno měl místo vícevláknového apartmánu (STA) jednovláknový byt (MTA), což je výchozí hodnota. Můžete to udělat dvěma způsoby:

  • Nejjednodušší způsob je přidat STAThreadAttribute (to znamená "[System.STAThreadAttribute()]") těsně nad první řádek metody aplikace Main (obvykle "static void Main(string[] args)").

  • Pokud potřebujete, aby byl stav vašeho Main vlákna , můžete umístit volání AddJob(String, String, Boolean) do samostatného vlákna, jehož stav bytu je nastaven na SetApartmentStateSTA .MTA Následující příklad ukazuje tuto druhou techniku.

Poznámka:

Nelze použít STAThreadAttribute u žádné metody s výjimkou Main a nelze použít SetApartmentState pro vlákno Main .

Další způsoby tisku ve Windows Presentation Foundation (WPF) zahrnují metoduPrintDialog.PrintDocument, kterou lze použít s dialogovým oknem nebo bez otevření dialogového XpsDocumentWriterokna a mnoho Write a WriteAsync metod .

Viz také

Platí pro

AddJob()

Vloží do fronty novou (obecně pojmenovanou Byte ) tiskovou úlohu, jejíž obsah je pole.

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

Návraty

A PrintSystemJobInfo , který představuje tiskovou úlohu a její stav.

Příklady

Následující příklad ukazuje, jak použít AddJob() k odeslání Byte pole do tiskové fronty. Tento kód funguje jenom s tiskárnami, které dokážou rozpoznat a tisknout prostý text. Některé z nich nemůžou.

// 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()

Poznámky

Tato metoda slouží k zápisu informací specifických pro zařízení do souboru zařazování, který není automaticky zahrnut do zařazování systému Microsoft Windows. Samozřejmě, že potřebujete vědět, zda soubor fondu je Enhanced Metafile (EMF) nebo XML Paper Specification (XPS). Pokud dáváte přednost práci s rozhraním Stream API, můžete místo této metody použít PrintQueueStream třídu.

AddJob Po zavolání metody je nutné napsat Byte pole do JobStream vlastnostiPrintSystemJobInfo, která je vrácena AddJob nebo není vytvořena žádná tisková úloha. Toto pole se vytiskne, pokud tiskárna funguje a není pozastavená.

Upozornění

JobStream Pokud není uzavřen s před koncem Close vlákna, ve kterém AddJob je volána, je InvalidOperationException vyvolána, když toto vlákno skončí, protože zařazovací vlákno nemůže získat kontrolu nad objektemStream.

V grafickém uživatelském rozhraní tiskové fronty má úloha název Tisk systémového dokumentu. Pokud chcete úlohu pojmenovat jinak, použijte AddJob(String) přetížení.

Další způsoby tisku ve Windows Presentation Foundation (WPF) zahrnují metoduPrintDialog.PrintDocument, kterou lze použít s dialogovým oknem nebo bez otevření dialogového XpsDocumentWriterokna a mnoho Write a WriteAsync metod .

Platí pro

AddJob(String)

Vloží novou tiskovou úlohu, jejíž obsah je Byte pole, do fronty.

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

Parametry

jobName
String

Název tiskové úlohy.

Návraty

A PrintSystemJobInfo , který představuje tiskovou úlohu a její stav.

Příklady

Následující příklad ukazuje, jak použít AddJob(String) ke čtení souboru do Byte pole a odeslání pole do tiskové fronty. Tento kód předpokládá, že v kořenovém adresáři jednotky C: existuje soubor s názvem test.txt. Tento kód funguje jenom s tiskárnami, které dokážou rozpoznat a tisknout prostý text. Některé z nich nemůžou.

// 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()

Poznámky

Tato metoda slouží k zápisu informací specifických pro zařízení do souboru zařazování, který není automaticky zahrnut do zařazování systému Microsoft Windows. Samozřejmě, že potřebujete vědět, zda soubor fondu je Enhanced Metafile (EMF) nebo XML Paper Specification (XPS). Pokud dáváte přednost práci s rozhraním Stream API, můžete místo této metody použít PrintQueueStream třídu.

AddJob Po zavolání metody je nutné napsat Byte pole do JobStream vlastnostiPrintSystemJobInfo, která je vrácena AddJob nebo není vytvořena žádná tisková úloha. Toto pole se vytiskne, pokud tiskárna funguje a není pozastavená.

Upozornění

JobStream Pokud není uzavřen s před koncem Close vlákna, ve kterém AddJob je volána, je InvalidOperationException vyvolána, když toto vlákno skončí, protože zařazovací vlákno nemůže získat kontrolu nad objektemStream.

Další způsoby tisku ve Windows Presentation Foundation (WPF) zahrnují metoduPrintDialog.PrintDocument, kterou lze použít s dialogovým oknem nebo bez otevření dialogového XpsDocumentWriterokna a mnoho Write a WriteAsync metod .

Platí pro