J4N
J4N

Reputation: 20717

How to print a Wpf components

I want to print a Framework element on a paper.

I'm currently having this:

    public static void Print(FrameworkElement frameworkElement)
    {
        PrintDialog dialog = new PrintDialog();
        if (dialog.ShowDialog() != true)
            return;
        frameworkElement.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
        frameworkElement.Arrange(new Rect(new Point(0, 0), frameworkElement.DesiredSize));
        dialog.PrintVisual(frameworkElement, "A Great Image.");
    }

but with this, my components doesn't takes the whole page, which is normal, because we ask him to paint with his desired size.

My second question about printing:

Can I do ONE print task, but print several components(one on each page?)

Thank you!

Upvotes: 1

Views: 2581

Answers (1)

Sergey Vedernikov
Sergey Vedernikov

Reputation: 7744

You should use PrintDocument class.

Example

Upvotes: 1

Related Questions