I have a huge data which I want to print using WPF. I found that WPF provides a PrintDialog.PrintVisual
method for printing any WPF control derived from the Visual
class.
PrintVisual
will only print a single page so I need to scale the control to fit on the page. Unfortunately this would not work for me since the report was sometimes long enough that it could not be read easily when scaled to fit on the page.
Another option for printing provided by WPF is to create a separate view in a FlowDocument
. This is probably the best way to print documents, but it was more work than I wished to put into it, not to mention the extra view that would have to be maintained for each control I wished to print.
I got another solution in this link, but it seems too complex for me.
Is there any better and simple solution for this ? Thanks for any help
I'm assuming your report is displayed in a DataGrid
or something else that is scrollable?
I believe FlowDocument
is definitely your best choice here if you want to print something that looks, for lack of a better word, professional. But if you want something quick and dirty, you could use a series of operations using RenderTargetBitmap.Render
. The basic process would be:
RenderTargetBitmap
RenderTargetBitmap.Render
on the DataGrid
or the ScrollViewer
that's containing the "large" controlAgain, don't call RenderTargetBitmap.Render
on the "large" control. Wrap the large control in a ScrollViewer
if it isn't already. That will essentially be your paginator.
I don't know if you'll be satisfied with the results, but this is the easiest method I can think of. It'll look like you manually hit PrintScreen
each time. Not sure if that's what you want, but if you want it to look nicer, I think you need to use FlowDocument
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With