我在平板电脑上有一个C#WPF桌面应用程序,该应用程序通过USB电缆连接到打印机。 当我尝试从应用程序向该特定打印机打印PDF报告时,出现以下错误:
{System.Printing.PrintQueueException: PrintTicket provider failed to retrieve PrintCapabilities. Win32 error: -2147467259
at MS.Internal.Printing.Configuration.PTProvider.GetPrintCapabilities(MemoryStream printTicket)
at System.Printing.PrintTicketManager.GetPrintCapabilitiesAsXml(PrintTicket printTicket)
at System.Printing.PrintTicketManager.GetPrintCapabilities(PrintTicket printTicket)
at System.Printing.PrintQueue.GetPrintCapabilities(PrintTicket printTicket)
at System.Windows.Controls.PrintDialog.UpdatePrintableAreaSize()
at System.Windows.Controls.PrintDialog.get_PrintableAreaWidth()
at PulmOne.MiniBox2.Reporting.Controls.ReportProcessor.GetPrintableArea(Size& pageSize, Rect& printableArea)
at PulmOne.MiniBox2.Reporting.Controls.ReportProcessor.<GetPageContentsAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PulmOne.MiniBox2.Reporting.Controls.ReportProcessor.<GetDocumentAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PulmOne.MiniBox2.Reporting.Controls.ReportProcessor.<GenerateDocumentAsync>d__c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PulmOne.MiniBox2.ReportsWpf.ReportWindow.<OnWindowLoaded>d__d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)}
我知道问题出在此代码行:
{var dialog = new PrintDialog();
pageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);}
有什么办法可以解决此问题,因此它适用于所有打印机吗?
谢谢!