修復PDF渲染超時問題
無法從 HTML 渲染 PDF 無法從 URL 渲染 PDF 從 HTML 產生 PDF 時發生錯誤 - 錯誤 從 URL 產生 PDF 時出錯 - 錯誤
- 未指定的本地異常
這些通用錯誤訊息表明 Chrome 渲染引擎遇到了故障。
應用以下程式碼片段將產生"Default.log"日誌文件,該文件可以協助確定故障原因。
// Enable logging for all events and set the file path for the log file.
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
IronPdf.Logging.Logger.LogFilePath = "Default.log";// Enable logging for all events and set the file path for the log file.
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
IronPdf.Logging.Logger.LogFilePath = "Default.log";' Enable logging for all events and set the file path for the log file.
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All
IronPdf.Logging.Logger.LogFilePath = "Default.log"渲染超時
逾時是 IronPDF 中實現的一項功能,旨在防止應用程式因 PDF 渲染時間過長而出現死鎖和無響應。 這可以透過管理資源來幫助用戶,確保 CPU、記憶體和網路頻寬等資源不會被耗時過長的進程佔用。 如果 PDF 渲染過程未能及時完成,將會拋出如下所述的逾時錯誤。
- 從 HTML 渲染 PDF 時,60 秒後逾時
- 從 URL 渲染 PDF 時逾時,60 秒後逾時 從 HTML 產生 PDF 時逾時 從 URL 產生 PDF 時逾時 從 HTML 渲染 PDF 時逾時 從 URL 渲染 PDF 時逾時
IronPDF 渲染時間過長可能由多種原因導致,例如渲染大型或大型 PDF、檢索用於渲染 PDF 的遠端資源/資產,或渲染本身出現問題。 但是,修改超時時長通常可以解決這個問題。
要覆蓋預設設置,使用者可以存取ChromePdfRenderOptions類別中的Timeout 屬性並將其設定為更高的值。
// Set the timeout for rendering to 120 seconds.
RenderingOptions.Timeout = 120; // seconds// Set the timeout for rendering to 120 seconds.
RenderingOptions.Timeout = 120; // seconds' Set the timeout for rendering to 120 seconds.
RenderingOptions.Timeout = 120 ' seconds從 2021.12.4995 版本開始,IronPDF 的預設渲染逾時時間為 60 秒。
渲染延遲
在某些情況下,IronPDF 可能會渲染:
空白PDF
- 內容不完整的PDF文件
- 缺少圖像資源的 PDF 文件
出現此問題的原因可能是,在從資源中檢索內容或資產的呼叫及時完成之前,PDF 文件就已經渲染完成。
對 PDF 渲染器施加渲染延遲通常有助於解決此問題。 這將指示渲染器將 PDF 渲染延遲一段設定的時間,以便在 PDF 渲染之前及時載入內容或資源。 為此,只需存取WaitFor包裝物件中的RenderDelay()方法,將所需的持續時間設定為方法參數,並將其作為ChromePdfRenderOptions屬性之一應用於渲染器。
// Set a render delay of 5000 milliseconds (5 seconds) to ensure content and assets are loaded before rendering.
RenderingOptions.WaitFor.RenderDelay(5000); // milliseconds// Set a render delay of 5000 milliseconds (5 seconds) to ensure content and assets are loaded before rendering.
RenderingOptions.WaitFor.RenderDelay(5000); // milliseconds' Set a render delay of 5000 milliseconds (5 seconds) to ensure content and assets are loaded before rendering.
RenderingOptions.WaitFor.RenderDelay(5000) ' milliseconds預設渲染延遲時間為 20 毫秒。
除了RenderDelay()方法之外, WaitFor包裝物件中還有其他方法可以利用。
有關日誌以及如何向我們的工程師報告錯誤以供審核的更多信息,請參閱如何為 IronPDF 提出工程支援請求。






