How to print something in WPF without using controls?

时间:2015-06-15 14:25:34

标签: c# wpf printing

I'm newbie in WPF and I'm trying to print student's exam papers using WPF and I'm creating exam papers using System.Drawing.Graphics and now I want to print them.

But it seems every printable thing in WPF is somehow a control. I have two problems:

  1. I don't know how can I print something that I've created via Graphics Like WinForms PrintDocument (that has it's own problems)
  2. I don't know how to create my exampaper in WPF like what I did with graphics.

would you help me with any of theses questions?

1 个答案:

答案 0 :(得分:2)

您可以利用PrintDocument类,而不是WPF特定的类。此类允许您将输出发送到打印机。应该处理PrintPage事件,您可以使用PrintPageEventArgs获取Graphics上下文;用于将检查绘制到打印机输出。这被认为是Winforms的打印方式。

WPF增强了printing命名空间提供的System.Printing支持。这些打印服务用于管理打印作业,发现打印队列和配置的打印机。 WPF中的打印通常通过生成XPS文档来执行,利用XpsDocumentWriter类&方法。但是,由于使用了System.Drawing.Graphics,因此也可以使用GDI打印,这是您可能需要的。请参阅GDI打印路径部分here