WPF:在没有打印对话框的情况下打印 FlowDocument
我正在 WPF 中编写一个笔记应用程序,为每个单独的笔记使用 FlowDocument
。该应用程序按标签搜索和过滤笔记。我想将当前过滤列表中的所有注释打印为单独的文档,并且只想在作业开始时显示一个打印对话框。
我在这个线程中找到了一个很好的打印示例,但它适合打印单个FlowDocument
,因此它使用 CreateXpsDocumentWriter()
重载来显示打印对话框。
所以,这是我的问题:任何人都可以建议一些好的代码来打印 FlowDocument
而不显示 PrintDialog
吗?我想我将在过程开始时显示“打印对话框”,然后循环浏览我的笔记集合以打印每个 FlowDocument
。
I am writing a note-taking application in WPF, using a FlowDocument
for each individual note. The app searches and filters notes by tags. I want to print all notes in the current filtered list as separate documents, and I only want to show a single Print Dialog at the beginning of the job.
I found a good print example in this thread, but it is geared toward printing a single FlowDocument
, so it uses a CreateXpsDocumentWriter()
overload that displays a Print Dialog.
So, here's my question: Can anyone suggest some good code for printing a FlowDocument
without displaying a PrintDialog
? I figure I'll display the Print Dialog at the beginning of the procedure and then loop through my notes collection to print each FlowDocument
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我重写了这个问题的答案,因为我确实找到了一种更好的方法来打印一组 FlowDocuments,同时仅显示一次打印对话框。答案来自 MacDonald,Pro WPF in C# 2008 (Apress 2008) 第 20 章,第 20 页。 704.
我的代码将一组 Note 对象捆绑到一个名为notesToPrint 的 IList 中,并从我的应用程序中的 DocumentServices 类获取每个 Note 的 FlowDocument。它设置 FlowDocument 边界以匹配打印机并设置 1 英寸边距。然后,它使用文档的 DocumentPaginator 属性打印 FlowDocument。代码如下:
这是一种非常简单的方法,有一个重大限制:它不异步打印。为此,您必须在后台线程上执行此操作,这就是我的做法。
I have rewritten my answer to this question, because I did find a better way to print a set of FlowDocuments, while showing the Print Dialog only once. The answer comes from MacDonald, Pro WPF in C# 2008 (Apress 2008) in Chapter 20 at p. 704.
My code bundles a set of Note objects into an IList called notesToPrint and gets the FlowDocument for each Note from a DocumentServices class in my app. It sets the FlowDocument boundaries to match the printer and sets a 1-inch margin. Then it prints the FlowDocument, using the document's DocumentPaginator property. Here's the code:
This is a pretty simple approach, with one significant limitation: It doesn't print asynchronously. To do that, you would have to perform this operation on a background thread, which is how I do it.
获得
printDialog
后只需一个循环。Just a loop after you have got the
printDialog
.