【问题标题】:How to print a pdf file in color using Adobe reader in C#如何在 C# 中使用 Adob​​e 阅读器以彩色打印 pdf 文件
【发布时间】:2020-05-27 15:25:36
【问题描述】:

在我的 C# winform 应用程序中,我使用 Adob​​e Reader DC 静默打印 pdf 文件。 pdf 文件应以彩色打印,但打印机设置的打印首选项为黑白。如何更改此属性并以编程方式将其设置为颜色。 这是我的静默打印代码:

public void StartPrinting(string fullFilePathForPrintProcess, string printerName)
        {
            string printApplicationPath = FindAdobeAcrobatPath();
            const string flagNoSplashScreen = "/s";
            const string flagOpenMinimized = "/h";

            var flagPrintFileToPrinter = string.Format("/t \"{0}\" \"{1}\"", fullFilePathForPrintProcess, printerName);

            var args = string.Format("{0} {1} {2}", flagNoSplashScreen, flagOpenMinimized, flagPrintFileToPrinter);

            var startInfo = new ProcessStartInfo
                            {
                                FileName = printApplicationPath,
                                Arguments = args,
                                CreateNoWindow = true,
                                ErrorDialog = false,
                                UseShellExecute = false,
                                WindowStyle = ProcessWindowStyle.Hidden
                            };

            var process = Process.Start(startInfo);

            // Close Acrobat regardless of version
            if (process != null)
            {
                process.WaitForInputIdle();
                process.CloseMainWindow();
                process.Dispose();
            }
        }

感谢任何帮助。

【问题讨论】:

  • “...Adobe Reader 的打印机属性始终设置为黑白”是什么意思?
  • @Formula12 抱歉解释不好,我有彩色 pdf 文档,我使用 Adob​​e Reader 打印它。但在打印机设置中,打印首选项设置为黑白。所以输出是黑白的。在网上进行了更多搜索后,我发现我需要通过我的 C# 代码更改打印首选项,但我仍然不知道如何。我非常感谢您的帮助。

标签: c# winforms pdf printing colors


【解决方案1】:

我想这就是你要找的东西

private void MyButtonPrint_OnClick(object sender, System.EventArgs e)
{

    // Set the printer name and ensure it is valid. If not, provide a message to the user.
    printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter";

    if (printDoc.PrinterSettings.IsValid) {

        // If the printer supports printing in color, then override the printer's default behavior.
        if (printDoc.PrinterSettings.SupportsColor) {

            // Set the page default's to print in color.
            printDoc.DefaultPageSettings.Color = true;
        }

        // Provide a friendly name, set the page number, and print the document.
        printDoc.DocumentName = "My Presentation";
        currentPageNumber = 1;
        printDoc.Print();
    }
    else {
        MessageBox.Show("Printer is not valid");
    }
}

完整代码见

Microsoft's documentation

【讨论】:

  • 感谢您的回复。我猜 printDocument 类不支持 pdf 文件。我说的对吗?
  • 如果回答了您的问题,请将答案标记为正确。
  • 我测试了 printDocument 类,看它是否打印 pdf 文件。不幸的是,事实并非如此。许多开发人员使用 pdf 库或 Adob​​e Reader 来执行它。
猜你喜欢
  • 1970-01-01
  • 2013-04-20
  • 2013-04-08
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
  • 2014-03-10
  • 1970-01-01
  • 2021-06-02
相关资源
最近更新 更多