Conversion Delay and Web Page Timeout with Html to Pdf Converter for .NET | |
For pages that use javascripts heavily, the conversion can be delayed a number of seconds using MinPageLoadTime property of the HtmlToPdfOptions object, to allow the content to be fully rendered.
In a similar way, if a page takes too much time to load, the converter can specify the amount of time in seconds when the page load will timeout using the property MaxPageLoadTime property of the HtmlToPdfOptions object.
By default, a navigation timeout raises an exception and no document is produced. Set RenderPageOnTimeout to true to convert whatever the page has rendered by the time the timeout expires instead. This is useful for pages that keep a connection open or poll indefinitely, where the content is complete long before the browser considers the navigation finished.
This sample code shows how the html to pdf converter can be used to convert a web page to pdf using Select.Pdf Pdf Library for .NET and how to set the conversion delay and timeout properties.
// instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // specify the number of seconds the conversion is delayed converter.Options.MinPageLoadTime = 2; // set the page timeout (in seconds) converter.Options.MaxPageLoadTime = 30; // render the page instead of raising an exception if the timeout expires converter.Options.RenderPageOnTimeout = true; // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(TxtUrl.Text); // save pdf document doc.Save(Response, false, "Sample.pdf"); // close pdf document doc.Close();