简体   繁体   English

C# - 打印 PDF 错误(System.ComponentModel.Win32Exception:...)

[英]C# - Print a PDF Error (System.ComponentModel.Win32Exception:...)

I am trying to write an application to print PDFs.我正在尝试编写一个打印 PDF 的应用程序。 Now I get an error message where I can't get any further after a long search.现在我收到一条错误消息,经过长时间的搜索,我无法进一步了解。

The goal would be to print a PDF file without opening the PDF-Reader.目标是在不打开 PDF 阅读器的情况下打印 PDF 文件。

My Code:我的代码:

using System.Diagnostics;



private void button1_Click(object sender, EventArgs e)
        {
            ProcessStartInfo info = new ProcessStartInfo();
            info.Verb = "print";
            info.FileName = @"C:\testFile.pdf";
            info.CreateNoWindow = true;
            info.WindowStyle = ProcessWindowStyle.Hidden;

            Process p = new Process();
            p.StartInfo = info;
            p.Start();

            p.WaitForInputIdle();
            System.Threading.Thread.Sleep(3000);
            if (false == p.CloseMainWindow())
                p.Kill();
        }

The error condition occurs at p.Start();错误情况发生在p.Start(); line.线。

Error message:错误信息:

System.ComponentModel.Win32Exception: "The system cannot find the specified file". System.ComponentModel.Win32Exception:“系统找不到指定的文件”。

New experience: 20.01.2021新体验:20.01.2021

If I comment out info.Verb = "print";如果我注释掉info.Verb = "print"; . . Then the PDF is opened.然后打开 PDF。 Is this a sign that it finds the PDF but has no access to printer?这是否表明它找到了 PDF 但无法访问打印机?

use this code it works for me:使用它对我有用的代码:

    public static void PrintToASpecificPirnter()
    {
        using (PrintDialog printDialog = new PrintDialog())
        {
            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                var StartInfo = new ProcessStartInfo();
                StartInfo.CreateNoWindow = true;
                StartInfo.UseShellExecute = true;
                StartInfo.Verb = "printTo";
                StartInfo.Arguments = "\"" + printDialog.PrinterSettings.PrinterName + "\"";
                StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                StartInfo.FileName = fileName;

                Process.Start(StartInfo);
            }
        }
    }

暂无
暂无

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

相关问题 System.ComponentModel.Win32Exception c# - System.ComponentModel.Win32Exception c# Selenium C#System.ComponentModel.Win32Exception'发生在System.dll错误中 - Selenium C# System.ComponentModel.Win32Exception' occurred in System.dll Error System.ComponentModel.Win32Exception:创建窗口处理程序C#时出错 - System.ComponentModel.Win32Exception: Error while creating a window handler C# 获取异常System.ComponentModel.Win32Exception:系统找不到Sikuli C#中指定的文件 - Getting an Exception System.ComponentModel.Win32Exception : The system cannot find the file specified in Sikuli C# 在窗口7中从c#打开叙述者时,system.componentmodel.win32exception = {“系统找不到指定的文件”}错误 - system.componentmodel.win32exception = {“the system cannot find the file specified”} error when opening narrator from c# in window 7 System.ComponentModel.Win32Exception:访问被拒绝...错误 - System.ComponentModel.Win32Exception: Access is denied… Error System.ComponentModel.Win32Exception:访问被拒绝错误 - System.ComponentModel.Win32Exception: Access is denied Error 简单更新查询导致 System.ComponentModel.Win32Exception: The wait operation timed out error in C# 和 SQL 服务器 - Simple update query caused System.ComponentModel.Win32Exception: The wait operation timed out error in C# and SQL Server C#Process.GetProcessById(4)引发System.ComponentModel.Win32Exception - C# Process.GetProcessById(4) throws System.ComponentModel.Win32Exception 找不到C#Mysql EF6代码优先System.ComponentModel.Win32Exception文件 - C# Mysql EF6 Code First System.ComponentModel.Win32Exception File not Found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM