0

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.

default locale
  • 13,035
  • 13
  • 56
  • 62
Suresh
  • 61
  • 7
  • Its been a while since I used wkhtmltopdf, but do the file paths for the header and footer need to be in quotations? (For other users unfamiliar with wkhtmltopdf, these are just command line arguments) – Sayse Jul 29 '14 at 07:02
  • no. it generates pdf well after my console application is closed – Suresh Jul 29 '14 at 07:05
  • I have no experience with wkhtmltopdf, but take a look on [this question](http://stackoverflow.com/questions/12517640/why-does-pdfkit-wkhtmltopdf-hang-but-renders-pdf-as-expected-when-rails-app-is-k) for possible problem description. And on [this one](http://stackoverflow.com/questions/1331926/calling-wkhtmltopdf-to-generate-pdf-from-html) for possible solution – default locale Jul 29 '14 at 07:08
  • I just checked my old code and it does surround the file paths for header/footer with quotes (My thoughts behind this comment was that it is hanging on trying to decipher the name) – Sayse Jul 29 '14 at 07:08
  • I have tried using quotes, does not make a difference, it too got created after closing my console window – Suresh Jul 29 '14 at 07:17
  • Do you need the number in the waitforexit? (That being said my code which is not written in .net waits for 10000 milliseconds instead of a minute) - Does your console application close on its own as well as generate the pdf if you wait for the minute? – Sayse Jul 29 '14 at 07:31

1 Answers1

0

Thanks everyone for contributing

Finally i have cracked it

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

Suresh
  • 61
  • 7