Search code examples
c#wpfprintingprintdialog

Printing not working in wpf


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?


Solution

  • 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