简体   繁体   中英

pdf Created after program exits

I m using wkhtmltopdf for creating pdf in a console application c#.net

The following is the code and

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

I expect the wkhtmltopdf.exe to exit at waitforexit line

But I can still see it in the memory and pdf is created with 0kb

If I close my console application, the pdf is created properly

This issue happens only when I use header and footer html in the arguments, else it works fine.

Thanks everyone for contributing

Finally i have cracked it

i added -q in the arguments, and it just worked fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM