我想使用 .net 在选定的打印机中打印任何文档,例如 pdf、word、excel 或文本文件。我已经成功在默认打印机中进行此类打印。现在唯一的问题是在选择的打印机。
这是打印代码。
public bool Print(string FilePath)
{
if (File.Exists(FilePath)) {
if (ShellExecute((System.IntPtr )1, "Print", FilePath, "", Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32() <= 32) {
return false;
} else {
return true;
}
} else {
return false;
}
}
最佳答案
Process printJob = new Process();
printJob.StartInfo.FileName = path;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printJob.StartInfo.Arguments = "\"" + printerAddress + "\"" + " " + printerExtraParameters;
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(path);
printJob.Start();
关于c# - 如何在选定的打印机中打印任何文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3138181/