Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C#使用Chrome将HTML转换为PDF_C#_Html_Pdf_Command Line Arguments - Fatal编程技术网

使用C#使用Chrome将HTML转换为PDF

使用C#使用Chrome将HTML转换为PDF,c#,html,pdf,command-line-arguments,C#,Html,Pdf,Command Line Arguments,我觉得我做错了什么,或者这是不可能的。我能够在命令提示符下运行,并使用下面代码中的路径创建pdf fine。有关详细信息,使用命令行时的参数字符串如下所示: chrome--headless--print to pdf=“c:\Users\pwtph82\desktop\myreport\myreport.pdf” 提前谢谢你的帮助 System.Diagnostics.Process process = new System.Diagnostics.Process();

我觉得我做错了什么,或者这是不可能的。我能够在命令提示符下运行,并使用下面代码中的路径创建pdf fine。有关详细信息,使用命令行时的参数字符串如下所示: chrome--headless--print to pdf=“c:\Users\pwtph82\desktop\myreport\myreport.pdf”

提前谢谢你的帮助

     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();

我不知道为什么它不允许我这么做。但您可以启动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(); 

我不知道为什么它不允许我这么做。但您可以启动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(); 

process.StartInfo.Arguments=“/C”+参数是什么做什么?为什么
chrome
包含在参数中?什么是
process.StartInfo.arguments=“/C”+参数做什么?为什么
chrome
包含在参数中?