修正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呈現過程未能在規定時間內完成,將會出現如下面所述的逾時錯誤。
- PDF從HTML呈現逾時,時間為60s
- PDF從URL呈現逾時,時間為60s
- 從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
呈現延遲
有時,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提出工程支援請求。

