解決 PDF 渲染超時問題
- 無法從 HTML 渲染 PDF
- 無法從 URL 渲染 PDF
- 從 HTML 生成 PDF/A 時發生錯誤
- 從 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"
渲染超時
超時 (Timeout) 是 IronPDF 中的一項功能,旨在防止應用程式因 PDF 渲染時間過長而陷入死鎖或無回應的狀態。 這有助於使用者管理資源,確保 CPU、記憶體和網路頻寬等資源不會被耗時過長的程序佔用。 若 PDF 渲染過程未能及時完成,將拋出如下所述的超時錯誤。
- 從 HTML 渲染 PDF/A 時,_60 秒_後超時
- 從 URL 渲染 PDF/A 時,_60 秒_後超時
- 從 HTML 生成 PDF/A 時發生超時
- 從 URL 生成 PDF 時發生超時
- 將 HTML 轉為 PDF 時發生超時
- 從 URL 渲染 PDF/A 時發生超時
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
渲染延遲
在某些情況下,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
除了 RenderDelay() 方法外,WaitFor 封裝物件中還有其他可供使用的方法。
如需進一步了解日誌相關資訊,以及如何向我們的工程師回報錯誤以供審查,請參閱《如何針對 IronPDF 提交工程支援請求》。

