asked on
[AllowAnonymous]
public ActionResult PrintSummaryPDF()
{
Process process = null;
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = ConfigurationManager.AppSettings["WkHtmlToPdfExePath"];
processStartInfo.Verb = "runas";
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
string fileNameDatePart = DateTime.Now.ToLongTimeString().Replace(":", string.Empty).Replace(" ", string.Empty);
string pdfFileName = "Survey" + fileNameDatePart + ".pdf";
processStartInfo.Arguments = HttpContext.Request.Url.AbsoluteUri.Replace("PrintSummaryPDF", "PrintSummary") + " " +
" --load-error-handling ignore" + " --cookie .ASPXAUTH " + Request.Cookies["DCCCDCookie"].Value + " \"" + ConfigurationManager.AppSettings["WkHtmlToPdfOutputPath"] + pdfFileName + "\"";
process = Process.Start(processStartInfo);
process.WaitForExit(Convert.ToInt32(ConfigurationManager.AppSettings["TimeOut"]));
int exitCode = process.ExitCode;
string stdout = process.StandardOutput.ReadToEnd();
string stderr = process.StandardError.ReadToEnd();
return File("../pdfoutput/" + pdfFileName, "application/pdf");
}
Qt: Untested Windows version 6.2 detected!
Loading pages (1/6)
[> ] 0%
[======> ] 10%
[================> ] 27%
[===================> ] 33%
[=======================> ] 39%
[============================> ] 47%
[=====================================> ] 62%
[========================================> ] 68%
[============================================> ] 74%
[================================================> ] 81%
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[==============================> ] Page 1 of 2
[============================================================] Page 2 of 2
Done
ASKER
. . .
var outputPath = ConfigurationManager.AppSettings["WkHtmlToPdfOutputPath"] + pdfFileName;
. . .
return File(outputPath, "application/pdf");
And that fixed it.ASKER
ASKER
process = Process.Start(processStartInfo);
process.WaitForExit(Convert.ToInt32(ConfigurationManager.AppSettings["TimeOut"]));
Is 'process' the handle on the response stream? In that case, I would do something like, process = Process.Start(processStartInfo);
process.WaitForExit(Convert.ToInt32(ConfigurationManager.AppSettings["TimeOut"]));
using (process)
{
using(var stream = new MemoryStream()) {
using(var responseStream = process.GetResponseStream()) {
responseStream.CopyTo(stream);
}
// now do whatever you're going to do; in this case, let's tell a little joke...
stream.Position = 0;
using(var reader = new StreamReader(stream)) {
// . . .
}
}
}
Is that how I obtain the handle on the response stream?The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
Of the Stack Trace you've shared, this appears to be the important part:
Open in new window
... the exceptions after that are subsequent failures because of this one.
Given the exception I'd wager that the stream being passed into the third-party library is from an HttpWebResponse... because those aren't searchable and as such don't support Position or Length. In the code that calls the library, instead of directly passing the stream from the response, try coping it into a MemoryStream first and pass that to the library. You can read more about the scenario here.