Javascript in HTML

Overview

By default, all Javascript code in the HTML is automatically executed the same way as they are loaded by a browser for viewing. This ensures the final render result is the same as viewed in a browser.

However if you wish to turn off Javascript, you can set HtmlToPdfOptions's NoScript to true. When this property is set to true, all Javascript code will be ignored. This can speed up the converting process, but the final result maybe different because scripts are not executed.

Some Web pages automatically generate/update the page or a portion of the page with Javascript after it loads. For example, a financial Web site may load the main contents right away but loads the real time stock quotes through a separate AJAX request. In order for the converter get a full "picture" of the Web page in such cases, it must wait long enough to give such scripts a chance to run. HtmlToPdfOptions's MinLoadWaitTime is introduced for this purpose. This property controls the minimum amount of time the converter should wait before the actual conversion starts.

Debug Console

EO.Pdf HTML to PDF converter can display debug or error message output from your JavaScript code. In order to trace such messages, you can set HtmlToPdf.DebugConsole to a TextWriter object. For example, the following code uses the standard output stream as the debug output console:

//Use the standard output console as the debug console
HtmlToPdf.DebugConsole = Console.Out;

With the above code, you can use the following code in your JavaScript to output debug message:

JavaScript
//Output debug message to the debug console
console.log("some debug message");

If an error occurred in your JavaScript code, the error message will also be outputted to the debug console.