Tôi đang cố gắng in tài liệu xps vào máy in (máy in mạng, một số máy in cục bộ ảo, xps và xps không dựa) với mã sau.PrintQueue.AddJob treo khi in tới máy in không phải xps
C# Nguồn:
static void Main(string[] args)
{
PrintServer printServer = new PrintServer(@"\\printserver.csez.zohocorpin.com");
foreach (PrintQueue queue in printServer.GetPrintQueues())
{
Console.WriteLine("Printer: {0}, Port: {1}, ShareName: {2}, status: {3}, PrintingIsCancelled: {4}",
queue.Name, queue.QueuePort.Name, queue.ShareName, queue.QueueStatus, queue.PrintingIsCancelled);
Program program = new Program();
Thread printingThread = new Thread(() => program.Print_XPXFile(queue, @"D:\Assist\RemotePrint\Spool\Donalduck.xps"));
// Set the thread that will use PrintQueue.AddJob to single threading.
printingThread.SetApartmentState(ApartmentState.STA);
printingThread.Start();
printingThread.Join();
}
}
public void Print_XPXFile(PrintQueue pQueue, String FilePath)
{
// Create print server and print queue.
bool fastCopy = pQueue.IsXpsDevice;
FileInfo file = new FileInfo(FilePath);
if (!file.Exists)
{
Console.WriteLine("There is no such file.");
}
else
{
Console.WriteLine("Adding {0} to {1} queue. share name : {2}", FilePath, pQueue.Name, pQueue.ShareName);
try
{
// Print the Xps file while providing XPS validation and progress notifications.
PrintSystemJobInfo xpsPrintJob = pQueue.AddJob(file.Name, FilePath, fastCopy);
Console.WriteLine("Done adding.");
}
catch (PrintJobException e)
{
Console.WriteLine("\n\t{0} could not be added to the print queue.", file.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.
}
else
{
Console.WriteLine("\tmessage : {0}", e.InnerException.Message);
}
}
}
}
Khi in cho Microsoft XPS Document Writer, Microsoft In sang PDF, vv nó hoạt động tốt.
Tôi thấy rằng nó hoạt động tốt với tất cả XPS based printers
. Tôi thậm chí đã cài đặt trình điều khiển máy in mẫu XPS và thêm máy in cục bộ ảo để xác nhận xác nhận quyền sở hữu này và như mong đợi nó hoạt động.
Đối với máy in không dựa trên xps, nó thực sự bị kẹt trong hàm AddJob. Nó không ném bất kỳ ngoại lệ nào, và nó cũng không chuyển sang câu lệnh tiếp theo.
Tôi đã phát triển mã dựa trên tài nguyên this msdn.
Nguyên nhân và giải pháp là gì?
Tất cả các ý tưởng đều được chào đón.
Thanx! Tôi vẫn cần phải biết nguyên nhân gốc rễ. Tôi sẽ chấp nhận câu trả lời này ngay bây giờ. Khi bất cứ ai khác đăng bài về nguyên nhân gốc rễ, tôi sẽ chấp nhận họ. –