With C# use Chrome to covert HTML to PDF

前端 未结 1 499
既然无缘
既然无缘 2020-12-11 13:45

I think I\'m doing something wrong or this isn\'t possible. I am able to run from the command prompt and create pdf fine using the paths in the code below. For more info t

相关标签:
1条回答
  • 2020-12-11 14:04

    I don't know why it doesn't allow me to do that. But you can start a powershell instance and run it through 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(); 
    
    0 讨论(0)
提交回复
热议问题