質問

I am developing wpf application. I have only one button in xaml page. On click of it I have written the following code

private void button1_Click(object sender, RoutedEventArgs e)
        {

            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                //PrintUsingDocumentCondensed("Hi", "Hello");
                printDialog.PrintVisual(button1, "Print123");
                //printDialog.PrintDocument("a",
            }
        }

I have attached printer to my system. When I click on print button in my application the printer start printing. The printer prints some text like BeginDefaults and EndDefaults, BeginResource and EndResource. Similary many other text. Also it print some text like 'This job requires more memory than is available in this printer', 'For output format choose optimize for portability', 'Reduce number of fonts in documents'. etc I think there is something going wrong with my printer. Or is there anything wrong with my code or application?. How should I print the actual button on print page with above code ? Can you please provide me any solution to the above link?

役に立ちましたか?

解決 2

I checked to print text on notepad. It was giving the same error. Then I analysed that printer is not added properly. It was my mistake. Now added printer properly. Everything is now working fine

他のヒント

I'm not sure why dropping the object directly in the PrintVisual method isn't working but I have a feeling this isn't the way you'll end up doing it anyway so I'd recommend going a different route. Instead of passing in the control I would generate a bitmap and then pass the bitmap into the PrintVisual method. This question handles how to do that:

Load image from file and print it using WPF... how?

And then here's a question that shows how to create a bitmap from a control.

Get a bitmap image from a Control view

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top