Ter*_* H 2 html c# pdf command-line-arguments
我想我做错了什么或者这是不可能的。我可以从命令提示符运行并使用下面代码中的路径创建 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)
我不知道为什么它不允许我这样做。但是您可以启动一个 powershell 实例并通过 powershell 运行它:
var process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
var chrome = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles(x86)"), @"Google\Chrome\Application\chrome.exe");
// use powershell
process.StartInfo.FileName = "powershell";
// set the Chrome path as local variable in powershell and run
process.StartInfo.Arguments = "$chrome='" + chrome + @"'; & $chrome --headless --print-to-pdf='c:\Users\" + Environment.UserName + @"\desktop\myReport.pdf' https://google.com";
process.Start();
Run Code Online (Sandbox Code Playgroud)