Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Redirecting STDIN is probably the easiest way to accomplish what you're trying to do.</p> <p>One method of redirecting STDIN with wkhtmltopdf (in ASP.Net) is as follows:</p> <pre><code> private void WritePDF(string HTML) { string inFileName, outFileName, tempPath; Process p; System.IO.StreamWriter stdin; ProcessStartInfo psi = new ProcessStartInfo(); tempPath = Request.PhysicalApplicationPath + "temp\\"; inFileName = Session.SessionID + ".htm"; outFileName = Session.SessionID + ".pdf"; // run the conversion utility psi.UseShellExecute = false; psi.FileName = "c:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe"; psi.CreateNoWindow = true; psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; // note that we tell wkhtmltopdf to be quiet and not run scripts // NOTE: I couldn't figure out a way to get both stdin and stdout redirected so we have to write to a file and then clean up afterwards psi.Arguments = "-q -n - " + tempPath + outFileName; p = Process.Start(psi); try { stdin = p.StandardInput; stdin.AutoFlush = true; stdin.Write(HTML); stdin.Close(); if (p.WaitForExit(15000)) { // NOTE: the application hangs when we use WriteFile (due to the Delete below?); this works Response.BinaryWrite(System.IO.File.ReadAllBytes(tempPath + outFileName)); //Response.WriteFile(tempPath + outFileName); } } finally { p.Close(); p.Dispose(); } // delete the pdf System.IO.File.Delete(tempPath + outFileName); } </code></pre> <p>Note that the code above assumes that there's a <em>temp</em> directory available in your application directory. Also, you must explicitly enable write access to that directory for the user account used when running the IIS process.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload