Beispiel #1
0
        public static void HTMLDocumentAsynchronouslyOnReadyStateChange()
        {
            //ExStart: HTMLDocumentAsynchronouslyOnReadyStateChange
            // Create the instance of HTML Document
            var document = new Aspose.Html.HTMLDocument();

            // Subscribe to the 'ReadyStateChange' event.
            // This event will be fired during the document loading process.
            document.OnReadyStateChange += (sender, @event) =>
            {
                // Check the value of 'ReadyState' property.
                // This property is representing the status of the document. For detail information please visit https://www.w3schools.com/jsref/prop_doc_readystate.asp
                if (document.ReadyState == "complete")
                {
                    Console.WriteLine(document.DocumentElement.OuterHTML);
                    Console.WriteLine("Loading is completed. Press any key to continue...");
                }
            };

            // Navigate asynchronously at the specified Uri
            document.Navigate("https://html.spec.whatwg.org/multipage/introduction.html");

            Console.WriteLine("Waiting for loading...");
            Console.ReadLine();
            //ExEnd: HTMLDocumentAsynchronouslyOnReadyStateChange
        }
Beispiel #2
0
        public static void HTMLDocumentAsynchronouslyOnLoad()
        {
            //ExStart: HTMLDocumentAsynchronouslyOnLoad
            // Create the instance of HTML Document
            var document = new Aspose.Html.HTMLDocument();

            // Subscribe to the 'OnLoad' event.
            // This event will be fired once the document is fully loaded.
            document.OnLoad += (sender, @event) =>
            {
                Console.WriteLine(document.DocumentElement.OuterHTML);
                Console.WriteLine("Loading is completed. Press any key to continue...");
            };

            // Navigate asynchronously at the specified Uri
            document.Navigate("https://html.spec.whatwg.org/multipage/introduction.html");

            Console.WriteLine("Waiting for loading...");
            Console.ReadLine();
            //ExEnd: HTMLDocumentAsynchronouslyOnLoad
        }
Beispiel #3
0
        public static void IndefiniteTimeout()
        {
            // ExStart:IndefiniteTimeout
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Data();

            // Create an instance of the HTML document
            using (var document = new Aspose.Html.HTMLDocument())
            {
                // Async loading of the external html file
                document.Navigate(dataDir + "input.html");

                // Create a renderer and output device
                using (HtmlRenderer renderer = new HtmlRenderer())
                    using (ImageDevice device = new ImageDevice(dataDir + @"document.png"))
                    {
                        // Delay the rendering indefinitely until there are no scripts or any other internal tasks to execute
                        renderer.Render(device, -1, document);
                    }
            }
            // ExEnd:IndefiniteTimeout
        }
Beispiel #4
0
        public static void Run()
        {
            // ExStart:RenderingTimeout
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Data();

            // Create an instance of the HTML document
            using (var document = new Aspose.Html.HTMLDocument())
            {
                // Async loading of the external html file
                document.Navigate(dataDir + "input.html");

                // Create a renderer and output device
                using (HtmlRenderer renderer = new HtmlRenderer())
                    using (ImageDevice device = new ImageDevice(dataDir + @"document.png"))
                    {
                        // Delay rendering for 5 seconds
                        // Note: document will be rendered into device if there are no scripts or any internal tasks to execute
                        renderer.Render(device, TimeSpan.FromSeconds(5), document);
                    }
            }

            // ExEnd:RenderingTimeout
        }