pdf程序退出后创建

本文关键字:创建 退出 程序 pdf | 更新日期: 2023-09-27 18:15:36

我正在使用wkhtmltopdf在控制台应用程序c#.net中创建pdf

下面是代码和

psi.UseShellExecute = false;
psi.FileName = "C:''Program Files''wkhtmltopdf''bin''wkhtmltopdf.exe";
psi.CreateNoWindow = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.Arguments = "--enable-javascript --no-stop-slow-scripts --javascript-delay 10000 --page-size A4 --dpi 300 --margin-top 20mm --header-html D:''header.html --margin-bottom 10mm  - --footer-html D:''footer.html  " + tempPath + "''" + outFileName;
p = Process.Start(psi);
try
{
    stdin = p.StandardInput;
    stdin.AutoFlush = true;
    stdin.Write(HTML);
    stdin.Close();
    p.WaitForExit(60000);
}
finally
{
    p.Close();
    p.Dispose();
}

我希望wkhtmltopdf.exe在waitforexit行退出

但是我仍然可以在内存中看到它,pdf是用0kb

创建的

如果我关闭控制台应用程序,pdf将被正确创建

只有当我在参数中使用页眉和页脚html时才会出现这个问题,否则它会正常工作。

pdf程序退出后创建

感谢大家的贡献

我终于破解了它

我在参数中添加了-q,它运行正常