c# - 我的打印方法保存 XPS 文件但不打印?

标签 c# printing xps

我的代码导致 saveFileDialog 保存 .xps 文件,而不是实际打印任何内容。我的代码有问题吗?如果没有,我该如何配置我的机器才能使此代码工作?

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();
    }
}

代码:

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

最佳答案

您的“Microsoft XPS Document Writer”打印机必须设置为默认打印机。

关于c# - 我的打印方法保存 XPS 文件但不打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4961592/

相关文章:

c# - 来自 MySQL 的报表查看器 C# 数据

oracle - 在 Oracle SQL Developer SQL Worksheet 窗口中打印文本

matlab - 在 matlab 中使用 parfor 保存高分辨率图形

xml - Docx 或 XPS(或一般的 ooxml)关系转换示例

c - 在 Xilinx Platform Studio 中映射端口并用 C 读取它

c# - Entity Framework MariaDb 日期作为字符串问题

c# - 在 UWP 中将 BitmapImage 转换为字节数组

c# - 检查字符串不为空、不为空且不为 "0000"的最简单方法是什么?

php - 使用PHP自动打印网页

c# - 从 XPS 文档中提取文本