Firoz
Firoz

Reputation: 7454

How can print text file in WPF

I have simple text file, and i have to print it using WPF. How can i print this file with specified printer setting(like margin, print on both side).

Upvotes: 2

Views: 7365

Answers (2)

Jason Harrison
Jason Harrison

Reputation: 965

Convert the file to a FlowDocument, then print that. The trick is in loading the text into the FlowDocument, See:

http://someblokeontheinternet.blogspot.com/2009/11/printing-contents-of-text-box-or-just.html

Upvotes: 3

Martin Liversage
Martin Liversage

Reputation: 106796

Microsoft has introduced a new printing API as part of WPF. You can read more about Printing and Print System Management on MSDN. You will have to format the text into an XPS document which you can then print. There is a sample on how to programmatically print XPS files.

Upvotes: 5

Related Questions