我在運行在.NET 4.0中的C#web應用程序中使用WkhtmltoPdf從HTML文件生成PDF。一般情況下,除非HTML文件的大小低於250KB,否則一切正常。一旦HTML文件的大小超過了這個範圍,那麼運行wkhtmltopdf.exe的過程將給出如下的例外。在任務管理器中,我已經看到wkhtmltopdf.exe進程的內存值不會增加超過40,096 K的值,我相信這是該進程被放棄的原因。在Asp.net中運行外部可執行文件的內存限制
如何配置外部exes的內存限制可以增加?有沒有其他解決這個問題的方法?
更多信息:
當我直接從命令行運行轉換時,PDF生成正常。所以,它不可能成爲WkhtmlToPdf的問題。
錯誤來自localhost。我已經在DEV服務器上嘗試了相同的結果。
編輯:
更具體的異常消息: - 對於 處理對象的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的調試器截圖過程:
也許這有助於:http://stackoverflow.com/a/9270159/135007 – ZippyV
你在哪裏看到任何事實這是一個內存不足的問題? –
@SimonMourier:從運行應用程序時,wkhtmltopdf.exe的內存值在任務管理器中的某個固定限制之後不會增加。而通過命令提示符運行相同的執行就好了。另外,如果輸入的HTML文件的大小較小,那麼通過應用程序就可以正常工作。在固定大小的HTML文件之後,即使是單個附加字符也不起作用。你認爲這可能是除記憶之外的其他問題嗎? – itsbalur