I am using Rotativa PDF print for an ASP.NET MVC application to create a pdf file from html content. This works great when starting an MVC application on its own on standard IIS; pdf is generated almost instantly.
But when the MVC application is deployed as a web role in Azure (both locally in dev and cloudapp.net), generating PDF print takes up to 45 seconds, and there also seems to be a problem with displaying resource resources (links are broken) . Something seems wrong, it should not take much time.
PDF generation itself is done using the wkhtmltopdf tool, which converts html content to PDF. wkhtmltopdf is executable and is executed using Process.Start, which is again called by the MVC application.
/// <summary> /// Converts given URL or HTML string to PDF. /// </summary> /// <param name="wkhtmltopdfPath">Path to wkthmltopdf.</param> /// <param name="switches">Switches that will be passed to wkhtmltopdf binary.</param> /// <param name="html">String containing HTML code that should be converted to PDF.</param> /// <returns>PDF as byte array.</returns> private static byte[] Convert(string wkhtmltopdfPath, string switches, string html) { // switches: // "-q" - silent output, only errors - no progress messages // " -" - switch output to stdout // "- -" - switch input to stdin and output to stdout switches = "-q " + switches + " -"; // generate PDF from given HTML string, not from URL if (!string.IsNullOrEmpty(html)) switches += " -"; var proc = new Process { StartInfo = new ProcessStartInfo { FileName = Path.Combine(wkhtmltopdfPath, "wkhtmltopdf.exe"), Arguments = switches, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, WorkingDirectory = wkhtmltopdfPath, CreateNoWindow = true } }; proc.Start(); // generate PDF from given HTML string, not from URL if (!string.IsNullOrEmpty(html)) { using (var sIn = proc.StandardInput) { sIn.WriteLine(html); } } var ms = new MemoryStream(); using (var sOut = proc.StandardOutput.BaseStream) { byte[] buffer = new byte[4096]; int read; while ((read = sOut.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } } string error = proc.StandardError.ReadToEnd(); if (ms.Length == 0) { throw new Exception(error); } proc.WaitForExit(); return ms.ToArray(); }
Does anyone have any ideas on what could cause problems and degrade performance?
Br.
M
source share