修正PDF呈現逾時問題

This article was translated from English: Does it need improvement?
Translated
View the article in English
  • 無法從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"
$vbLabelText   $csharpLabel

呈現逾時

逾時是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
$vbLabelText   $csharpLabel

請注意從版本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
$vbLabelText   $csharpLabel

請注意預設RenderDelay持續時間為20毫秒

除了RenderDelay()方法,WaitFor包裝物件中還有其他可以利用的方法。

有關日誌和如何向我們的工程師報告錯誤以供審查的更多資訊,請參閱如何為IronPDF提出工程支援請求

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備開始了嗎?
Nuget 下載 20,296,129 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在捲動嗎?

想快速獲得證明嗎? PM > Install-Package IronPdf
執行範例 看您的HTML變成PDF。