拦截 PrintDialog 到 XPS Document Writer

发布于 2024-10-18 05:30:39 字数 269 浏览 4 评论 0原文

目前我为用户提供两个控件:保存和打印。当用户选择“保存”时,WPF 显示的一个区域将被打包并通过 XpsDocumentWriter 发送,并且提示并鼓励用户签署新的 xps 文档。当用户选择“打印”时,PrintDialog.PrintVisual 会将同一区域打印到用户选择的打印机。

一切都很好,只是 Microsoft XPS Document Writer 是打印机的选择之一。有没有办法阻止或拦截用户对 XPS 文档编写器的选择并将其发送到 Save 方法,以便我可以提示用户签署 XPS 文档?

Currently I am providing the user with two controls: Save and Print. When the user selects Save, a region of the WPF display is packaged up and sent through a XpsDocumentWriter and the user is prompted and encouraged to sign the new xps document. When the user selects Print, a PrintDialog.PrintVisual prints that same region to a user selected printer.

All well and good, except that Microsoft XPS Document Writer is one of the choices for printers. Is there a way to prevent or intercept the user selection of XPS document writer and send them to the Save method so I can prompt the user to sign the xps document?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2024-10-25 05:30:39

免责声明:我以前从未使用过 PrintDialog,但看起来像这样的东西可能会起作用:

System.Windows.Controls.PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
    PrintQueue selectedQueue = printDialog.PrintQueue;
    if (selectedQueue.Name == "Microsoft XPS Document Writer")
    {
        // Run your XPS save & sign code
    }
    else
    {
        // Run your printDialog.PrintVisual() code
    }
}

我真的不喜欢将打印机名称硬编码(我假设它随语言设置而变化)。可能有更好的属性 PrintQueue 您可以使用它来识别这台打印机。

Disclaimer: I've never used PrintDialog before, but it looks like something like this might work:

System.Windows.Controls.PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
    PrintQueue selectedQueue = printDialog.PrintQueue;
    if (selectedQueue.Name == "Microsoft XPS Document Writer")
    {
        // Run your XPS save & sign code
    }
    else
    {
        // Run your printDialog.PrintVisual() code
    }
}

I don't really like having the printer name hard-coded (I assume it varies with language settings). Possibly there is a better property of PrintQueue that you can use to identify this printer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文