c# - '指定的可执行文件不是此操作系统平台的有效应用程序
问题描述
我想在没有用户交互的情况下从 C# 代码打印 PDF 文件。
我尝试了这个公认的答案,但它对我不起作用。
这是我试过的代码:
Process p = new Process();
p.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "print",
FileName = @"G:\Visual Studio Projects\PrintWithoutGUI\PrintWithoutGUI\Courses.pdf" //put the correct path here
};
p.Start();
我得到这个例外:
System.ComponentModel.Win32Exception:'指定的可执行文件不是此 OS 平台的有效应用程序。'`
解决方案
通过添加 UseShellExecute=true尝试此操作,它将打印到默认打印机,但如果您想打印到特定的打印,则通过指定打印机的名称Arguments属性将动词print 更改为动词 printTo 。
private static void PrintByProcess()
{
using (Process p = new Process())
{
p.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
UseShellExecute=true,
Verb = "print",
FileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\doc.pdf"
};
p.Start();
}
推荐阅读
- android - 在 RecyclerView 中显示 SQLite 数据
- r - 按日期列在彼此范围内合并数据框
- opendaylight - restconf:配置 BGP 对等体的正确 api 调用是什么
- swift - Swift:将灰度图像转换为包含视差的 CVPixelBuffer
- c# - C# Winform - DAL 和 BLL - 使用静态方法好吗?
- python - 有没有办法将特定推文的直接 URL 转换为 JSON 格式?
- amazon-web-services - 使用 Lambda 在 AWS Codestar 中安装 Python 依赖项
- java - 我的 Java 正则表达式从不匹配,尽管它总是通过在线 Java 正则表达式检查器
- css - css3中的flex在safari mobile中不起作用
- python - 数组覆盖其他先前插入的数据