WPF - PrintTicket provider failed to bind to printer.
프린터 설정 대화창을 띄우는 데 문제가 발생했습니다.
코드는 너무 간단합니다. 빈 프로젝트 하나 만들고 다음과 같이 달랑 2 라인을 추가했는데, ShowDialog 호출 후 오류가 발생합니다.
private void button1_Click(object sender, RoutedEventArgs e)
{
PrintDialog pd = new PrintDialog();
pd.ShowDialog();
}
PrintDialog 내부의 코드와 네트워크 프린터로 연결된 구형 레이저 프린터간의 뭔가 충돌이 발생하는 것 같다는 정도!
재현 과정도 매우 단순합니다. 위의 코드를 실행시킨 후, 버튼을 누르면 프린터 설정화면이 아래와 같이 뜹니다.
[그림 1: 프린터 설정 대화창]
위의 상태에서, 단지 "삼성 ML-8700G"라는 항목을 선택한 것만으로도 아래와 같이 대화창의 "Apply" 버튼이 활성화 됩니다.
[그림 2: "Apply" 버튼 활성]
이제 그냥 "Cancel" 버튼을 누르면 아래와 같이 예외가 발생합니다.
[그림 3: "Cancel" 버튼 누르면 예외 발생]
System.Printing.PrintQueueException was unhandled
Message="PrintTicket provider failed to bind to printer.
Win32 error: The specified resource type cannot be found in the image file.\r\n"
Source="ReachFramework"
PrinterName="\\\\testpc\\삼성 ML-8700G"
StackTrace:
at MS.Internal.Printing.Configuration.PTProvider..ctor(String deviceName, Int32 maxVersion, Int32 clientVersion)
at System.Printing.Interop.PrintTicketConverter..ctor(String deviceName, Int32 clientPrintSchemaVersion)
at MS.Internal.Printing.Win32PrintDialog.PrintDlgExMarshaler.AcquirePrintTicket(IntPtr devModeHandle, String printQueueName)
... [중간 생략] ...
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
뭐 좀... 과정이라도 복잡해야 어떻게 된지 문제라도 좀 분석해 볼텐데... ^^;
웹을 검색해 봐도 딱히 신통한 답이 없네요. 그래서 제가 선택한 방법은, Windows Forms에서 제공되는 프린터 대화창을 사용한 것입니다. 그래서 아래와 같이 코드를 교체하면 문제가 해결된다는. ^^;
private void button1_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.PrintDialog pd = new System.Windows.Forms.PrintDialog();
pd.ShowDialog();
}
[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]