Printing Images and Graphics Using WPF

Using (or providing) Microsoft.NET Classes

Printing Images and Graphics Using WPF

Postby Dick Bowman on Fri Jan 17, 2014 3:24 pm

Would appreciate some pointers to succinct simple examples of printing graphics using WPF - already have a rudimentary understanding of how to print text.

Here's the scenario...

An application can display (2D) graphics two ways, either by drawing vector images (lines, polygons, etc.) onto a Canvas, or by populating an Image. What I want to do now is transfer these graphics to a printer.

My hunt online has - as usual - thrown up a bewildering collection of code examples in other programming languages, but no obvious "start here if you are a novice" article.

My interpretation for the vector case is that I could just replicate the drawing process, but to a printery-thing rather than the screen. Not keen on that because the drawing process is quite time consuming, what I want to do is just say - in effect - "take what's on the Canvas and send it to the printer object".

For the Image case I think (probably wrongly) that it ought to be a case of following a similar route as for text-print but instead of adding content to a FlowDocument there should be some other type of container (but what might it be?).

Simple answers preferred, thank you...
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: Printing Images and Graphics Using WPF

Postby PGilbert on Sun Mar 23, 2014 9:50 pm

Hello Dick, recently we developped a function called PrintVisual to print what WPF call a 'Visual'. An Image and a Canvas are objects falling into that category. What we needed was to print the current screen of our application to the printer with a border around it and centered on the paper while using the default printer. In the case of an Image (or Canvas) object you just need to do: PrintVisual visualObject, where visualObject is the .net visual object.

There is numerous articles on that subject but we found that when the visual object has more pixels than the page of the printer (visual needed to be shrink) we were not able to make it work with the online examples. What is good with WPF is that the visual object does not need to be visible on the screen to work, it could be part of a Window that is minimize or out of focus. The visual object does not need to be visible at all !

Since we are using a FlowDocument you can easily add some title or other .net objects to the Visual Object once you get used to the FlowDocument syntax. Hopefully what we have developped will be close to what you are looking for.

Vive APL

PrintVisual.txt
(6.4 KiB) Downloaded 893 times
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Printing Images and Graphics Using WPF

Postby Dick Bowman on Mon Mar 24, 2014 5:45 pm

Thanks - I'll take a look. Not sure when, some other stuff is taking priority at the moment. I'll get back as and when.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest