Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing in C# (wpf)

Tags:

c#

printing

wpf

I'm making a C# WPF program, and my program has to be able to print invoices, but I'm kinda struggling to find out how printing works in WPF... If I remember well from programming in winforms, there you'd use GDI+ to print. However, I assume that's not the case with WPF.

I would be very happy if someone could point me in the right direction with some links to helpful documents or examples...

like image 831
Sander Declerck Avatar asked Apr 14 '11 09:04

Sander Declerck


People also ask

What is printf and scanf in C?

Printf() and Scanf() are inbuilt library functions in C language that perform formatted input and formatted output functions. These functions are defined and declared in stdio. h header file. The 'f' in printf and scanf stands for 'formatted'.

How do I print in printf?

Generally, printf() function is used to print the text along with the values. If you want to print % as a string or text, you will have to use '%%'.

Can you write printf in C?

printf (print formatted) in C, writes out a cstring to stdout (standard output). The provided cstring may contain format specifiers( beginning with % in the cstring). If there are format specifiers, those are replaced with their respective arguments that follow the cstring to the printf call.


1 Answers

Printing in WPF is both simple and not so simple.

It starts with basically with one or two lines of code you are printing already.

private void PrintBtn_Click(object sender, RoutedEventArgs e) {     PrintDialog printDialog = new PrintDialog();     if (printDialog.ShowDialog() == true)     {     printDialog.PrintVisual(grid, "My First Print Job");     } } 

However, pagination in WPF is not done with a single line of code. Then you get into FlowDocuments and similar more advanced topics.

If you are making a non-commercial tool for yourself, consider iTextSharp which is very good too.

like image 101
Jaapjan Avatar answered Sep 29 '22 08:09

Jaapjan