How can I print something in WPF without using controls?

I am new to WPF and I am trying to print student exam papers using WPF and I am creating exam papers using System.Drawing.Graphics

and now I want to print them.

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

  • I don't know how I can print something that I have created via Graphics

    Like WinForms PrintDocument

    (which has its own problems)
  • I don't know how to create an exam in WPF like what I did with graphics.

Would you help me with any of these questions?

+3


source to share


1 answer


You can use the PrintDocument class , which is not WPF specific. This class allows you to send output to a printer. The PrintPage event must be handled when you use the PrintPageEventArgs to get the Graphics context; which is used to output the exam to the printer output. This is considered the Winforms way of printing.



WPF has improved the support provided by the System.Printing namespace. These print services are used to manage print jobs and to find print queues and configured printers. Printing to WPF is usually done by creating an XPS document using the XpsDocumentWriter class and methods . However, GDI printing is also available, which you will probably need due to the use of System.Drawing.Graphics. See the GDI Print Path section here .

+2


source







All Articles