修复 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渲染延迟
在某些情况下,IronPDF 可能会渲染:
- 空白 PDF
- 内容不完整的 PDF
- 缺少图像资产的 PDF
此问题可能是因为 PDF 文档在调用获取内容或资产的资源完成之前被渲染。
为 PDF 渲染器应用渲染延迟通常有助于解决问题。 这将指示渲染器延迟 PDF 渲染,以便内容或资产可以及时加载,然后再进行 PDF 渲染。 为此,只需在 RenderDelay() 方法中访问 WaitFor 包装对象,将所需的持续时间作为方法参数进行设置,然后将其作为 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 提出工程支持请求。






