Beispiel #1
0
        public static void RendererTimeoutExample()
        {
            //ExStart: RendererTimeoutExample
            // Prepare an HTML code
            var code = @"
            <script>
                var count = 0;
                setInterval(function()
                    {
                        var element = document.createElement('div');
                        var message = (++count) + '. ' + 'Hello World!!';
                        var text = document.createTextNode(message);
                        element.appendChild(text);
                        document.body.appendChild(element);
                    }, 1000);
            </script>
            ";

            // Initialize an HTML document based on prepared HTML code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Create an instance of HTML Renderer
                using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
                {
                    // Create an instance of PDF device
                    using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf"))
                    {
                        // Render HTML to PDF
                        renderer.Render(device, System.TimeSpan.FromSeconds(5), document);
                    }
                }
            }
            //ExEnd: RendererTimeoutExample
        }
Beispiel #2
0
        public static void CustomMessageHandler()
        {
            //ExStart: CustomMessageHandler
            // Prepare an HTML code with missing image file
            var code = @"<img src='missing.jpg'>";

            System.IO.File.WriteAllText("document.html", code);

            // Create an instance of Configuration
            using (var configuration = new Aspose.Html.Configuration())
            {
                // Add ErrorMessageHandler to the chain of existing message handlers
                var network = configuration.GetService <Aspose.Html.Services.INetworkService>();
                network.MessageHandlers.Add(new LogMessageHandler());

                // Initialize an HTML document with specified configuration
                // During the document loading, the application will try to load the image and we will see the result of this operation in the console.
                using (var document = new Aspose.Html.HTMLDocument("document.html", configuration))
                {
                    // Convert HTML to PNG
                    Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(), "output.png");
                }
            }
            //ExEnd: CustomMessageHandler
        }
Beispiel #3
0
        public static void SpecifyPDFPermissions()
        {
            //ExStart: SpecifyPDFPermissions
            // Prepare an HTML code
            var code = @"<div>Hello World!!</div>";

            // Initialize the HTML document from the HTML code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Create the instance of Rendering Options
                var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();

                // Set the permissions to the file
                options.Encryption = new Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionInfo(
                    "user_pwd",
                    "owner_pwd",
                    Aspose.Html.Rendering.Pdf.Encryption.PdfPermissions.PrintDocument,
                    Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionAlgorithm.RC4_128);

                // Create the PDF Device and specify options and output file
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf"))
                {
                    // Render HTML to PDF
                    document.RenderTo(device);
                }
            }
            //ExEnd: SpecifyPDFPermissions
        }
Beispiel #4
0
        private static void SaveUsingHTMLSaveOptions()
        {
            //ExStart: SaveUsingHTMLSaveOptions
            string dataDir = RunExamples.GetDataDir_Data();

            using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", "about:blank"))
            {
                // Create options object
                Aspose.Html.Saving.HTMLSaveOptions options = new Aspose.Html.Saving.HTMLSaveOptions();

                // Set the maximum depth of resource which will be handled.
                // Depth of 1 means that only resources directly referenced from the saved document will be handled.
                // Setting this property to -1 will lead to handling of all resources.
                // Default value is 3
                options.ResourceHandlingOptions.MaxHandlingDepth = 1;

                // This property is used to set restriction applied to handlers of external resources.
                // SameHost means that only resources located at the same host will be saved.
                options.ResourceHandlingOptions.UrlRestriction = Aspose.Html.Saving.UrlRestriction.SameHost;

                // This property is used to setup processing behaviour of any type of resource.
                // ResourceHandling.Save means all resources will be saved to the output folder
                options.ResourceHandlingOptions.Default = Aspose.Html.Saving.ResourceHandling.Save;

                // This property is used to set up processing behaviour of particular 'application/javascript' mime type.
                // In our case all scripts will be skipped during saving
                options.ResourceHandlingOptions.JavaScript = Aspose.Html.Saving.ResourceHandling.Discard;

                // Save the document
                document.Save(dataDir + "SaveUsingHTMLSaveOptions_out.html", options);
            }
            //ExEnd: SaveUsingHTMLSaveOptions
        }
Beispiel #5
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 #6
0
        public static void UsingDOM()
        {
            //ExStart: UsingDOM
            // Create the instance of HTML Document
            using (var document = new Aspose.Html.HTMLDocument())
            {
                // Create the style element and assign the green color for all elements with class-name equals 'gr'.
                var style = document.CreateElement("style");
                style.TextContent = ".gr { color: green }";

                // Find the document header element and append style element to the header
                var head = document.GetElementsByTagName("head").First();
                head.AppendChild(style);

                // Create the paragraph element with class-name 'gr'.
                var p = (Aspose.Html.HTMLParagraphElement)document.CreateElement("p");
                p.ClassName = "gr";

                // Create the text node
                var text = document.CreateTextNode("Hello World!!");

                // Append the text node to the paragraph
                p.AppendChild(text);

                // Append the paragraph to the document body element
                document.Body.AppendChild(p);

                // Create the instance of the PDF output device and render the document into this device
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf"))
                    document.RenderTo(device);
            }
            //ExEnd: UsingDOM
        }
Beispiel #7
0
        public static void SpecifyUserStyleSheet()
        {
            //ExStart: SpecifyUserStyleSheet
            // Prepare an HTML code and save it to the file.
            var code = @"<span>Hello World!!!</span>";

            System.IO.File.WriteAllText("document.html", code);

            // Create an instance of Configuration
            using (var configuration = new Aspose.Html.Configuration())
            {
                // Get the IUserAgentService
                var userAgent = configuration.GetService <Aspose.Html.Services.IUserAgentService>();

                // Set the custom color to the SPAN element
                userAgent.UserStyleSheet = "span { color: green; }";

                // Initialize an HTML document with specified configuration
                using (var document = new Aspose.Html.HTMLDocument("document.html", configuration))
                {
                    // Convert HTML to PDF
                    Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf");
                }
            }
            //ExEnd: SpecifyUserStyleSheet
        }
Beispiel #8
0
        public static void SpecifyCustomStreamProvider()
        {
            //ExStart: SpecifyCustomStreamProvider
            // Create an instance of MemoryStreamProvider
            using (var streamProvider = new MemoryStreamProvider())
            {
                // Initialize an HTML document
                using (var document = new Aspose.Html.HTMLDocument(@"<span>Hello</span> <span>World!!</span>", "."))
                {
                    // Convert HTML to Image by using the MemoryStreamProvider
                    Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), streamProvider);

                    // Get access to the memory stream that contains the result data
                    var memory = streamProvider.Streams.First();
                    memory.Seek(0, System.IO.SeekOrigin.Begin);

                    // Flush the result data to the output file
                    using (System.IO.FileStream fs = System.IO.File.Create("output.jpg"))
                    {
                        memory.CopyTo(fs);
                    }
                }
            }
            //ExEnd: SpecifyCustomStreamProvider
        }
Beispiel #9
0
        public static void SpecifyRenderingOptions()
        {
            //ExStart: SpecifyRenderingOptions
            // Prepare an HTML code
            var code = @"<span>Hello World!!</span>";

            // Initialize the HTML document from the HTML code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Create the instance of PdfRenderingOptions and set a custom page-size
                var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions()
                {
                    PageSetup =
                    {
                        AnyPage = new Aspose.Html.Drawing.Page(
                            new Aspose.Html.Drawing.Size(
                                Aspose.Html.Drawing.Length.FromInches(5),
                                Aspose.Html.Drawing.Length.FromInches(2)))
                    }
                };

                // Create the PDF Device and specify options and output file
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf"))
                {
                    // Render HTML to PDF
                    document.RenderTo(device);
                }
            }
            //ExEnd: SpecifyRenderingOptions
        }
Beispiel #10
0
        public static void CombineMultipleHTMLToPDF()
        {
            //ExStart: CombineMultipleHTMLToPDF
            // Prepare an HTML code
            var code1 = @"<br><span style='color: green'>Hello World!!</span>";
            var code2 = @"<br><span style='color: blue'>Hello World!!</span>";
            var code3 = @"<br><span style='color: red'>Hello World!!</span>";

            // Create three HTML documents to merge later
            using (var document1 = new Aspose.Html.HTMLDocument(code1, "."))
                using (var document2 = new Aspose.Html.HTMLDocument(code2, "."))
                    using (var document3 = new Aspose.Html.HTMLDocument(code3, "."))
                    {
                        // Create an instance of HTML Renderer
                        using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
                        {
                            // Create an instance of PDF device
                            using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf"))
                            {
                                // Merge all HTML documents into PDF
                                renderer.Render(device, document1, document2, document3);
                            }
                        }
                    }
            //ExEnd: CombineMultipleHTMLToPDF
        }
Beispiel #11
0
        public static void SpecifyLeftRightPageSize()
        {
            //ExStart: SpecifyLeftRightPageSize
            // Prepare an HTML code
            var code = @"<style>div { page-break-after: always; }</style>
            <div>First Page</div>
            <div>Second Page</div>
            <div>Third Page</div>
            <div>Fourth Page</div>";

            // Initialize the HTML document from the HTML code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Create the instance of Rendering Options and set a custom page-size
                var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
                options.PageSetup.SetLeftRightPage(
                    new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(400, 200)),
                    new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(400, 100))
                    );

                // Create the PDF Device and specify options and output file
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf"))
                {
                    // Render HTML to PDF
                    document.RenderTo(device);
                }
            }
            //ExEnd: SpecifyLeftRightPageSize
        }
Beispiel #12
0
        public static void CSSSelectorUsageExample()
        {
            //ExStart: CSSSelectorUsageExample
            // Prepare an HTML code
            var code = @"
                <div class='happy'>
                    <div>
                        <span>Hello</span>
                    </div>
                </div>
                <p class='happy'>
                    <span>World!</span>
                </p>
            ";

            // Initialize a document based on the prepared code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Here we create a CSS Selector that extract all elements whose 'class' attribute equals to 'happy' and their child SPAN elements
                var elements = document.QuerySelectorAll(".happy span");

                // Iterate over the resulted list of elements
                foreach (Aspose.Html.HTMLElement element in elements)
                {
                    System.Console.WriteLine(element.InnerHTML);
                    // output: Hello
                    // output: World!
                }
            }
            //ExEnd: CSSSelectorUsageExample
        }
Beispiel #13
0
        public static void AdjustPageSizeToContent()
        {
            //ExStart: AdjustPageSizeToContent
            // Prepare an HTML code
            var code = @"<style>
                div { page-break-after: always; }
            </style>
            <div style='border: 1px solid red; width: 400px'>First Page</div>
            <div style='border: 1px solid red; width: 600px'>Second Page</div>
            ";

            // Initialize the HTML document from the HTML code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Create the instance of Rendering Options and set a custom page-size
                var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
                options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(500, 200));

                // Enable auto-adjusting for the page size
                options.PageSetup.AdjustToWidestPage = true;

                // Create the PDF Device and specify options and output file
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf"))
                {
                    // Render HTML to PDF
                    document.RenderTo(device);
                }
            }
            //ExEnd: AdjustPageSizeToContent
        }
Beispiel #14
0
        public static void SpecifyBackgroundColor()
        {
            //ExStart: SpecifyBackgroundColor
            // Prepare an HTML code and save it to the file.
            var code = @"<p>Hello World!!</p>";

            System.IO.File.WriteAllText("document.html", code);

            // Create an instance of HTML document
            using (var document = new Aspose.Html.HTMLDocument("document.html"))
            {
                // Initialize options with 'cyan' as a background-color
                var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions()
                {
                    BackgroundColor = System.Drawing.Color.Cyan
                };

                // Create an instance of PDF device
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf"))
                {
                    // Render HTML to PDF
                    document.RenderTo(device);
                }
            }
            //ExEnd: SpecifyBackgroundColor
        }
Beispiel #15
0
        public static void XPathQueryUsageExample()
        {
            //ExStart: XPathQueryUsageExample
            // Prepare an HTML code
            var code = @"
                <div class='happy'>
                    <div>
                        <span>Hello!</span>
                    </div>
                </div>
                <p class='happy'>
                    <span>World</span>
                </p>
            ";

            // Initialize a document based on the prepared code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Here we evaluate the XPath expression where we select all child SPAN elements from elements whose 'class' attribute equals to 'happy':
                var result = document.Evaluate("//*[@class='happy']//span",
                                               document,
                                               null,
                                               Aspose.Html.Dom.XPath.XPathResultType.Any,
                                               null);

                // Iterate over the resulted nodes
                for (Aspose.Html.Dom.Node node; (node = result.IterateNext()) != null;)
                {
                    System.Console.WriteLine(node.TextContent);
                    // output: Hello
                    // output: World!
                }
            }
            //ExEnd: XPathQueryUsageExample
        }
Beispiel #16
0
        public static void NodeFilterUsageExample()
        {
            //ExStart: NodeFilterUsageExample
            // Prepare an HTML code
            var code = @"
                <p>Hello</p>
                <img src='image1.png'>
                <img src='image2.png'>
                <p>World!</p>";

            // Initialize a document based on the prepared code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // To start HTML navigation we need to create an instance of TreeWalker.
                // The specified parameters mean that it starts walking from the root of the document, iterating all nodes and use our custom implementation of the filter
                using (var iterator = document.CreateTreeWalker(document, Aspose.Html.Dom.Traversal.Filters.NodeFilter.SHOW_ALL, new OnlyImageFilter()))
                {
                    // Use
                    while (iterator.NextNode() != null)
                    {
                        // Since we are using our own filter, the current node will always be an instance of the HTMLImageElement.
                        // So, we don't need the additional validations here.
                        var image = (Aspose.Html.HTMLImageElement)iterator.CurrentNode;

                        System.Console.WriteLine(image.Src);
                        // output: image1.png
                        // output: image2.png
                    }
                }
            }
            //ExEnd: NodeFilterUsageExample
        }
Beispiel #17
0
        public static void EditCSS()
        {
            //ExStart: EditCSS
            // Create an instance of HTML Document with specified content
            var content = "<style>p { color: red; }</style><p>Hello World!</p>";

            using (var document = new Aspose.Html.HTMLDocument(content, "."))
            {
                // Find the paragraph element to inspect the styles
                var paragraph = (Aspose.Html.HTMLElement)document.GetElementsByTagName("p").First();

                // Get the reference to the IViewCSS interface.
                var view = (Aspose.Html.Dom.Css.IViewCSS)document.Context.Window;

                // Get the calculated style value for the paragraph node
                var declaration = view.GetComputedStyle(paragraph);

                // Read the "color" property value out of the style declaration object
                System.Console.WriteLine(declaration.Color); // rgb(255, 0, 0)

                // Set the green color to the paragraph
                paragraph.Style.Color = "green";

                // Create the instance of the PDF output device and render the document into this device
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf"))
                    document.RenderTo(device);
            }
            //ExEnd: EditCSS
        }
Beispiel #18
0
        public static void SpecifyImageSpecificOptions()
        {
            //ExStart: SpecifyImageSpecificOptions
            // Prepare an HTML code
            var code = @"<div>Hello World!!</div>";

            // Initialize an instance of HTML document based on prepared code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Create an instance of Rendering Options
                var options = new Aspose.Html.Rendering.Image.ImageRenderingOptions()
                {
                    Format = Aspose.Html.Rendering.Image.ImageFormat.Jpeg,

                    // Disable smoothing mode
                    SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None,

                    // Set the image resolution as 75 dpi
                    VerticalResolution   = Aspose.Html.Drawing.Resolution.FromDotsPerInch(75),
                    HorizontalResolution = Aspose.Html.Drawing.Resolution.FromDotsPerInch(75),
                };


                // Create an instance of Image Device
                using (var device = new Aspose.Html.Rendering.Image.ImageDevice(options, "output.jpg"))
                {
                    // Render HTML to Image
                    document.RenderTo(device);
                }
            }
            //ExEnd: SpecifyImageSpecificOptions
        }
Beispiel #19
0
 protected override void Render(string sourcePath, IDevice device)
 {
     using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(sourcePath))
     {
         HtmlRenderer renderer = new HtmlRenderer();
         renderer.Render(device, html_document);
     }
 }
 ///<Summary>
 /// ConvertHtmlToMhtml to convert html file to mhtml
 ///</Summary>
 public Response ConvertHtmlToMhtml(string fileName, string folderName)
 {
     return(ProcessTask(fileName, folderName, ".mhtml", false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
     {
         Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(inFilePath);
         document.Save(outPath, Html.Saving.HTMLSaveFormat.MHTML);
     }));
 }
Beispiel #21
0
        public static void SpecifyResolution()
        {
            //ExStart: SpecifyResolution
            // Prepare an HTML code and save it to the file.
            var code = @"
                <style>
                p
                { 
                    background: blue; 
                }
                @media(min-resolution: 300dpi)
                {
                    p 
                    { 
                        /* high resolution screen color */
                        background: green
                    }
                }
                </style>
                <p>Hello World!!</p>";

            System.IO.File.WriteAllText("document.html", code);

            // Create an instance of HTML document
            using (var document = new Aspose.Html.HTMLDocument("document.html"))
            {
                // Create options for low-resolution screens
                var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions()
                {
                    HorizontalResolution = 50,
                    VerticalResolution   = 50
                };

                // Create an instance of PDF device
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output_resolution_50.pdf"))
                {
                    // Render HTML to PDF
                    document.RenderTo(device);
                }


                // Create options for high-resolution screens
                options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions()
                {
                    HorizontalResolution = 300,
                    VerticalResolution   = 300
                };

                // Create an instance of PDF device
                using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output_resolution_300.pdf"))
                {
                    // Render HTML to PDF
                    document.RenderTo(device);
                }
            }
            //ExEnd: SpecifyResolution
        }
Beispiel #22
0
 ///<Summary>
 /// ConvertHtmlToMhtml to convert html file to mhtml
 ///</Summary>
 public Response ConvertHtmlToMhtml(string[] fileNames, string folderName)
 {
     return(ProcessTask((inFilePath, outPath, zipOutFolder) =>
     {
         string fileName = fileNames[0];
         Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(fileName);
         document.Save(outPath, Html.Saving.HTMLSaveFormat.MHTML);
     }));
 }
Beispiel #23
0
 private static void FromHTML()
 {
     //ExStart: FromHTML
     using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", "."))
     {
         // do some actions over the document here...
     }
     //ExEnd: FromHTML
 }
Beispiel #24
0
 private static void FromRemoteURL1()
 {
     //ExStart: FromRemoteURL1
     using (var document = new Aspose.Html.HTMLDocument(new Url("http://your.site.com/")))
     {
         // do some actions over the document here...
     }
     //ExEnd: FromRemoteURL1
 }
Beispiel #25
0
 private static void FromScratch()
 {
     //ExStart: FromScratch
     using (var document = new Aspose.Html.HTMLDocument())
     {
         // do some actions over the document here...
     }
     //ExEnd: FromScratch
 }
Beispiel #26
0
        public static void FillFormAndSubmitIt()
        {
            //ExStart: FillFormAndSubmitIt
            // Initialize an instance of HTML document from 'https://httpbin.org/forms/post' url
            using (var document = new Aspose.Html.HTMLDocument(@"https://httpbin.org/forms/post"))
            {
                // Create an instance of Form Editor
                using (var editor = Aspose.Html.Forms.FormEditor.Create(document, 0))
                {
                    // You can fill the data up using direct access to the input elements, like this:
                    editor["custname"].Value = "John Doe";

                    document.Save("out.html");

                    // or this:
                    var comments = editor.GetElement <Aspose.Html.Forms.TextAreaElement>("comments");
                    comments.Value = "MORE CHEESE PLEASE!";

                    // or even by performing a bulk operation, like this one:
                    editor.Fill(new Dictionary <string, string>()
                    {
                        { "custemail", "*****@*****.**" },
                        { "custtel", "+1202-555-0290" }
                    });

                    // Create an instance of form submitter
                    using (var submitter = new Aspose.Html.Forms.FormSubmitter(editor))
                    {
                        // Submit the form data to the remote server.
                        // If you need you can specify user-credentials and timeout for the request, etc.
                        var result = submitter.Submit();

                        // Check the status of the result object
                        if (result.IsSuccess)
                        {
                            // Check whether the result is in json format
                            if (result.ResponseMessage.Headers.ContentType.MediaType == "application/json")
                            {
                                // Dump result data to the console
                                Console.WriteLine(result.Content.ReadAsString());
                            }
                            else
                            {
                                // Load the result data as an HTML document
                                using (var resultDocument = result.LoadDocument())
                                {
                                    // Inspect HTML document here.
                                }
                            }
                        }
                    }
                }
            }
            //ExEnd: FillFormAndSubmitIt
        }
        public static void Run()
        {
            // ExStart:LoadHtmlUsingURL
            String InputHtml = "http://aspose.com/";

            // Load HTML file using Url instance
            Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(new Aspose.Html.Url(InputHtml));
            // Print inner HTML of file to console
            Console.WriteLine(document.Body.InnerHTML);
            // ExEnd:LoadHtmlUsingURL
        }
Beispiel #28
0
        private static void FromLocalFile()
        {
            //ExStart: FromLocalFile
            string dataDir = RunExamples.GetDataDir_Data();

            using (var document = new Aspose.Html.HTMLDocument(dataDir + "input.html"))
            {
                // do some actions over the document here...
            }
            //ExEnd: FromLocalFile
        }
Beispiel #29
0
 public static void HTMLDocumentFromURL()
 {
     //ExStart: HTMLDocumentFromURL
     // Load a document from 'https://html.spec.whatwg.org/multipage/introduction.html' web page
     using (var document = new Aspose.Html.HTMLDocument("https://html.spec.whatwg.org/multipage/introduction.html"))
     {
         // Write the document content to the output stream.
         Console.WriteLine(document.DocumentElement.OuterHTML);
     }
     //ExEnd: HTMLDocumentFromURL
 }
Beispiel #30
0
        private static void SaveToFile()
        {
            //ExStart: SaveToFile
            string dataDir = RunExamples.GetDataDir_Data();

            using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", "about:blank"))
            {
                document.Save(dataDir + "SaveToFile_out.html");
            }
            //ExEnd: SaveToFile
        }