ASP.NETMVCアプリケーションのRotativaPDF印刷を使用して、htmlコンテンツからpdfを生成しています。これは、MVCアプリケーションを標準のIISで単独で実行する場合に最適です。PDFはほぼ瞬時に生成されます。
ただし、MVCアプリケーションがAzureでWebロールとして展開されている場合(開発環境とcloudapp.netの両方でローカル)、PDF印刷の生成には最大45秒かかり、コンテンツリソースの表示にも問題があるようです(リンクが壊れています) 。何かがおかしいようです、それほど長くはかからないはずです。
pdfの生成自体は、htmlコンテンツをPDFに変換するwkhtmltopdfツールを使用して行われます。wkhtmltopdfは実行可能ファイルであり、MVCアプリケーションによって再度呼び出されるProcess.Startを使用して実行されます。
/// <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();
}
何が問題を引き起こし、パフォーマンスを低下させているのかについて誰かが何か考えを持っていますか?
Br。
M