我想我做错了什么或者这是不可能的。我可以从命令提示符运行并使用下面代码中的路径创建 pdf 文件。有关详细信息,当我使用命令行时,参数字符串如下所示: chrome --headless --print-to-pdf="c:\Users\pwtph82\desktop\myreport\myreport.pdf" https://google.com
感谢您提前提供的任何帮助。
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo.FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
string arguments = @"chrome --headless --print-to-pdf=""c:\\Users\pwtph82\desktop\myreport\myReport.pdf"" https://google.com";
process.StartInfo.Arguments = "/C " + arguments;
process.Start();
Run Code Online (Sandbox Code Playgroud)