C# --headless print-to-pdf with Microsoft edge(chromium) won't work using ProcessStartInfo

61 views Asked by At

It works when using Chrome.
I wanted Edge as a back-up for printing HTML to PDF as it is pre-installed on Windows.
Process.ExitCode gives out 1002 and no error in BeginErrorReadLine. And no PDF is generated at output path unlike Chrome.

if(File.Exists(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")
     string FilePath = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
Process process = new Process();
process.StartInfo.FileName = FilePath;
string pdfFile = //output-path(in Temp);
string htmlFile = //input-file-path(in Temp);

process.StartInfo.Arguments = $"--headless --print-to-pdf-no-header --disable-gpu --run-all-compositor-stages-before-draw --print-to-pdf={pdfFile} {htmlFile}";

process.Start();
process.WaitForExit();
Console.WriteLine(process.ExitCode);
0

There are 0 answers