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



在我的C# wform应用程序中,我使用Adobe 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();
}
}

任何帮助,不胜感激。

我认为这就是你要找的

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的文档

最新更新