JavaScript訊息監聽器
使用 IronPDF 的 ChromePdfRenderOptions.JavascriptMessageListener
屬性,您可以新增一個方法回呼,在瀏覽器控制台訊息變為可用時被調用。 了解更多有關此功能的信息,請造訪IronPDF 文件 - Javascript 控制台訊息.
using IronPdf; using System; var renderOptions = new ChromePdfRenderOptions { // Method callback to be invoked whenever a browser console message becomes available: JavascriptMessageListener = message => Console.WriteLine($"JS: {message}"), Javascript = "console.log('foo');", }; var pdf = new ChromePdfRenderer { RenderingOptions = renderOptions }.RenderHtmlAsPdf("<h1> Hello World </h1>"); // Example of JavaScript that will cause an error: renderOptions.Javascript = "document.querySelector('non-existent').style.color='foo';"; // message => Uncaught TypeError: Cannot read properties of null (reading 'style')
Imports IronPdf Imports System Private renderOptions = New ChromePdfRenderOptions With { .JavascriptMessageListener = Sub(message) Console.WriteLine($"JS: {message}"), .Javascript = "console.log('foo');" } Private pdf = New ChromePdfRenderer With {.RenderingOptions = renderOptions}.RenderHtmlAsPdf("<h1> Hello World </h1>") ' Example of JavaScript that will cause an error: renderOptions.Javascript = "document.querySelector('non-existent').style.color='foo';" ' message => Uncaught TypeError: Cannot read properties of null (reading 'style')
Install-Package IronPdf
使用 IronPDF 的 ChromePdfRenderOptions.JavascriptMessageListener
屬性,您可以新增一個方法回呼,在瀏覽器控制台訊息變為可用時被調用。 了解更多有關此功能的信息,請造訪IronPDF 文件 - Javascript 控制台訊息.