Esempio n. 1
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
        }
Esempio n. 2
0
        public static void HTMLWithoutLinkedFile()
        {
            //ExStart: HTMLWithoutLinkedFile
            // Prepare a simple HTML file with a linked document.
            System.IO.File.WriteAllText("document.html", "<p>Hello World!</p>" +
                                        "<a href='linked.html'>linked file</a>");
            // Prepare a simple linked HTML file
            System.IO.File.WriteAllText("linked.html", "<p>Hello linked file!</p>");

            // Load 'document.html' into memory
            using (var document = new Aspose.Html.HTMLDocument("document.html"))
            {
                // Create Save Options instance
                var options = new Aspose.Html.Saving.HTMLSaveOptions();

                // The following line with value '0' cut off all other linked HTML-files while saving this instance.
                // If you remove this line or change value to the '1', the 'linked.html' file will be saved as well to the output folder.
                options.ResourceHandlingOptions.MaxHandlingDepth = 1;

                // Save the document
                document.Save(@".\html-to-file-example\document.html", options);
            }
            //ExEnd: HTMLWithoutLinkedFile
        }