在AC#VSTO开关触发印刷之前,当前的打印机要颜色(打印机默认为黑色和白色)

发布于 2025-02-12 18:19:51 字数 1841 浏览 1 评论 0原文

我正在尝试说服一个VSTO Word加载程序,以设置打印机(将由Defult To Black-White设置)在调用WD.ActivedOcument.printout之前用颜色打印此文档。


        printerSettings = new PrinterSettings();
        try
        {
            printerSettings.PrinterName = wb.ActivePrinter;
        }
        catch
        {
        }

        var pageSettings = new PageSettings(printerSettings);

        //To Reset after printout
        var printerColourDefaultSetting = printerSettings.DefaultPageSettings.Color;
        var printColourSettings = pageSettings.Color;

        

        if (PrinterSettings.SupportsColor) //I'd hope only one of these -but neither work
        {
            PrinterSettings.DefaultPageSettings.Color = true;
            pageSettings.Color = true;
        }
        else
        {
            //doesn't support colour
        }


      object Background = true;
        object Append = false;
        object Range = PrintOutRange;
        object To = missing;
        object From = missing;
        if (PrintOutRange == WdPrintOutRange.wdPrintFromTo)
        {
            To = LastPage.ToString(CultureInfo.InvariantCulture);
            From = FirstPage.ToString(CultureInfo.InvariantCulture);
        }
        object Copies = NoCopies;
        object PrintToFile = false;
        object Collate = true;


        wb.ActiveDocument.PrintOut(ref Background, ref Append, ref Range, ref missing, ref From, ref To,
                                            ref missing,
                                            ref Copies, ref missing, ref missing, ref PrintToFile, ref Collate,
                                            ref missing, ref missing,
                                            ref missing, ref missing, ref missing, ref missing);

但是,使用此代码,我设置的PageSttings和DefaultPagesettings设置被忽略。有什么想法将其迫使文档的颜色变成颜色?

I'm trying to persuade a VSTO Word add-in to set the printer (which will be set by defult to black-and-white) to print this document in colour prior to calling wd.ActiveDocument.PrintOut


        printerSettings = new PrinterSettings();
        try
        {
            printerSettings.PrinterName = wb.ActivePrinter;
        }
        catch
        {
        }

        var pageSettings = new PageSettings(printerSettings);

        //To Reset after printout
        var printerColourDefaultSetting = printerSettings.DefaultPageSettings.Color;
        var printColourSettings = pageSettings.Color;

        

        if (PrinterSettings.SupportsColor) //I'd hope only one of these -but neither work
        {
            PrinterSettings.DefaultPageSettings.Color = true;
            pageSettings.Color = true;
        }
        else
        {
            //doesn't support colour
        }


      object Background = true;
        object Append = false;
        object Range = PrintOutRange;
        object To = missing;
        object From = missing;
        if (PrintOutRange == WdPrintOutRange.wdPrintFromTo)
        {
            To = LastPage.ToString(CultureInfo.InvariantCulture);
            From = FirstPage.ToString(CultureInfo.InvariantCulture);
        }
        object Copies = NoCopies;
        object PrintToFile = false;
        object Collate = true;


        wb.ActiveDocument.PrintOut(ref Background, ref Append, ref Range, ref missing, ref From, ref To,
                                            ref missing,
                                            ref Copies, ref missing, ref missing, ref PrintToFile, ref Collate,
                                            ref missing, ref missing,
                                            ref missing, ref missing, ref missing, ref missing);

However, with this code both the pageSettings and DefaultPageSettings settings I've set are being ignored. Any ideas how to force this into colour for a document?

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

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

发布评论

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

评论(1

烟花肆意 2025-02-19 18:19:51

“对象模型”一词不提供选择打印机的属性或方法。我想当您调用打印输出方法时,将使用默认一个。

您可以使用Windows API设置默认打印机:

using System.Runtime.InteropServices;
//
public static class PrinterClass
{
        [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool SetDefaultPrinter(string Printer);
}
//
PrinterClass.SetDefaultPrinter("Paste your desired Printer Name here");

请参阅如何在C#中设置Windows默认打印机?以获取更多信息。

The Word object model doesn't provide property or method for choosing a printer. I guess the default one will be used when you call the PrintOut method.

You can use the Windows API to set the default printer:

using System.Runtime.InteropServices;
//
public static class PrinterClass
{
        [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool SetDefaultPrinter(string Printer);
}
//
PrinterClass.SetDefaultPrinter("Paste your desired Printer Name here");

See How do I set the windows default printer in C#? for more information.

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