简体   繁体   English

如何在 C# 中使用 Adobe 阅读器以彩色打印 pdf 文件

[英]How to print a pdf file in color using Adobe reader in C#

In my C# winform application, I print silently a pdf file by using Adobe Reader DC.在我的 C# winform 应用程序中,我使用 Adobe Reader DC 静默打印 pdf 文件。 The pdf file should be printed in color, but the printing preferences of printer's settings is on Black and White. pdf 文件应以彩色打印,但打印机设置的打印首选项为黑白。 How can I change this property and set it on color programmatically.如何更改此属性并以编程方式将其设置为颜色。 Here is my code to print silently:这是我静默打印的代码:

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

Any help is appreciated.任何帮助表示赞赏。

I think this is what you're looking for我想这就是你要找的

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

Full code can be found at完整代码可以在

Microsoft's documentation 微软的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM