简体   繁体   English

WPF DocumentViewer - 无需确认即可打印

[英]WPF DocumentViewer - Print with no confirmation

I have a WPF application where I use a document viewer. 我有一个WPF应用程序,我使用文档查看器。 I also start printing programmatically with documentviewer.Print(); 我也开始使用documentviewer.Print()进行编程打印; However, when that is pressed it brings up the screen with the Windows printers and makes the user have to click "OK" again on that screen to start. 但是,当按下该按钮时,它会使用Windows打印机调出屏幕,并使用户必须再次单击该屏幕上的“确定”才能启动。 Is there a way to avoid the confirmation and make documentviewer.Print(); 有没有办法避免确认并制作documentviewer.Print(); immediately start the print job on the default Windows printer? 立即在默认的Windows打印机上启动打印作业?

All you need is the default print queue, which you can get via 您只需要默认的打印队列,您可以通过它来获取

var pq = LocalPrintServer.GetDefaultPrintQueue()

From this, you can create an XpsDocumentWriter : 从这里,您可以创建一个XpsDocumentWriter

var writer = PrintQueue.CreateXpsDocumentWriter(pq);

Now, you can get the DocumentPaginator from your DocumentViewer via the Document property , which returns an IDocumentPaginatorSource that has a DocumentPaginator property : 现在,你可以得到DocumentPaginator经由您的DocumentViewer 文档属性 ,它返回一个的IDocumentPaginatorSource DocumentPaginator属性

var paginator = documentviewer.Document.DocumentPaginator;

and you can send that right to the XpsDocumentWriter's Write method : 并且您可以将该权限发送到XpsDocumentWriter的Write方法

writer.Write(paginator);

Simple, isn't it? 简单,不是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM