My Print Method Saves An XPS File But Doesn't Print?

1.3k views Asked by At

My code results in a saveFileDialog to save a .xps file instead of actually printing anything. Is there something wrong with my code? If not, how can I configure my machine to make this code work?

class Printer {
    public Printer() {
    }

    private void PrintDocument_PrintPage(Object sender, PrintPageEventArgs e) {
        Font printFont = new Font("Courier New", 12);
        e.Graphics.DrawString(StringToPrint, printFont, Brushes.Black, 0, 0);
    }

    private PrintDocument pd = new PrintDocument();
    private string StringToPrint;

    public void PrintString(string input) {
        pd.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
        StringToPrint = input;
        pd.Print();
    }
}

Code:

Printer Printer = new Printer();
Printer.PrintString("Hello world");
1

There are 1 answers

1
Russell McClure On BEST ANSWER

It must be that your "Microsoft XPS Document Writer" printer is setup as your default printer.