HTML ファイルから PDF を生成するために、.NET 4.0 で実行されている C# Web アプリケーションで WkhtmltoPdf を使用しています。一般に、HTML ファイルのサイズが 250KB 未満の場合を除き、すべて正常に動作します。HTML ファイルのサイズがそれを超えると、wkhtmltopdf.exe を実行するプロセスで次のような例外が発生します。タスク マネージャーで、wkhtmltopdf.exe プロセスのメモリ値が 40,096 K の値を超えて増加しないことを確認しました。これがプロセスが途中で中止された理由だと思います。
外部exeのメモリ制限を増やすことができるように構成するにはどうすればよいですか? この問題を解決する他の方法はありますか?
詳細:
コマンド ラインから直接変換を実行すると、PDF が正常に生成されます。したがって、WkhtmlToPdf で問題になる可能性は低いです。
エラーはローカルホストからのものです。DEVサーバーでも同じことを試しましたが、同じ結果になりました。
編集:
より具体的な例外メッセージ: - Process オブジェクトの MainModule プロパティの場合、エラーは - {"ReadProcessMemory または WriteProcessMemory 要求の一部のみが完了しました"}、NativeErrorCode 値 - 299 を示します。
例外:
> [Exception: Loading pages (1/6) [>
> ] 0% [======> ]
> 10% [======> ] 11%
> [=======> ] 13%
> [=========> ] 15%
> [==========> ] 18%
> [============> ] 20%
> [=============> ] 22%
> [==============> ] 24%
> [===============> ] 26%
> [=================> ] 29%
> [==================> ] 31%
> [===================> ] 33%
> [=====================> ] 35%
> [======================> ] 37%
> [========================> ] 40%
> [=========================> ] 42%
> [==========================> ] 44%
> [============================> ] 47%
> [=============================> ] 49%
> [==============================> ] 51%
> [============================================================] 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 49 [==>
> ] Page 2 of 49 [===>
> ] Page 3 of 49 [====>
> ] Page 4 of 49 [======>
> ] Page 5 of 49 [=======>
> ] Page 6 of 49 [========>
> ] Page 7 of 49 [=========>
> ] Page 8 of 49 [==========>
> ] Page 9 of 49 [============>
> ] Page 10 of 49 [=============>
> ] Page 11 of 49 [==============>
> ] Page 12 of 49 [===============>
> ] Page 13 of 49 [================>
> ] Page 14 of 49 [==================>
> ] Page 15 of 49 [===================>
> ] Page 16 of 49 [====================>
> ] Page 17 of 49 [=====================>
> ] Page 18 of 49 [======================>
> ] Page 19 of 49 [========================>
> ] Page 20 of 49 [=========================>
> ] Page 21 of 49 [==========================>
> ] Page 22 of 49 [===========================>
> ] Page 23 of 49 [============================>
> ] Page 24 of 49 [==============================>
> ] Page 25 of 49 [===============================>
> ] Page 26 of 49 [=================================>
> ] Page 27 of 49 [==================================>
> ]
私が使用するコード:
var fileName = " - ";
var wkhtmlDir = ConfigurationManager.AppSettings[Constants.AppSettings.ExportToPdfExecutablePath];
var wkhtml = ConfigurationManager.AppSettings[Constants.AppSettings.ExportToPdfExecutablePath] + "\\wkhtmltopdf.exe";
var p = new Process();
string switches = "";
switches += "--print-media-type ";
switches += "--margin-top 10mm --margin-bottom 10mm --margin-right 5mm --margin-left 5mm ";
switches += "--page-size A4 ";
switches += "--disable-smart-shrinking ";
var startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
FileName = wkhtml,
Arguments = switches + " " + url + " " + fileName,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput=true,
WorkingDirectory=wkhtmlDir
};
p.StartInfo = startInfo;
p.Start();
WkHtmlToPdf.exe プロセスのデバッガーのスクリーンショット: