@ruhongcai
Thank you for being patient.
We would like to share with you that the ticket HTMLNET-1140 has been resolved and now you can save all resources inside HTML files and also remove all JavaScript.
To receive HTML file without JavaScript you need to disable scripts execution, or they will be executed during parsing.
Aspose.Html.Configuration config = new Aspose.Html.Configuration();
config.Security |= Aspose.Html.Sandbox.Scripts;
Then you can configure resources handling behavior with new Aspose.Html.Saving.HTMLSaveOptions
class.
Aspose.Html.Saving.HTMLSaveOptions saveOptions = new
Aspose.Html.Saving.HTMLSaveOptions();
//This will disable depth filter, which will lead to saving of all referenced resources.
saveOptions.ResourceHandlingOptions.MaxHandlingDepth = -1;
//To handle only local resources user can set according URL restriction.
saveOptions.ResourceHandlingOptions.UrlRestriction = Aspose.Html.Saving.UrlRestriction.SameHost;
//This option is used to embed resources in to HTML files.
saveOptions.ResourceHandlingOptions.Default = Aspose.Html.Saving.ResourceHandling.Embed;
//This option is used to discard all JS.
saveOptions.ResourceHandlingOptions.JavaScript = Aspose.Html.Saving.ResourceHandling.Discard;
As a result you will receive three HTML files which contain all local resources embedded in to them, except JavaScript that was discarded.
Complete usage example will look like this:
using (Aspose.Html.Configuration config = new Aspose.Html.Configuration())
{
config.Security |= Aspose.Html.Sandbox.Scripts;
using (Aspose.Html.HTMLDocument doc = new Aspose.Html.HTMLDocument(@"C:\inputFolder\index.html", config))
{
Aspose.Html.Saving.HTMLSaveOptions saveOptions = new Aspose.Html.Saving.HTMLSaveOptions();
//This will disable depth filter, which will lead to saving of all referenced resources.
saveOptions.ResourceHandlingOptions.MaxHandlingDepth = -1;
//To handle only local resources user can set according URL restriction.
saveOptions.ResourceHandlingOptions.UrlRestriction = Aspose.Html.Saving.UrlRestriction.SameHost;
//This option is used to embed resources in to HTML files.
saveOptions.ResourceHandlingOptions.Default = Aspose.Html.Saving.ResourceHandling.Embed;
//This option is used to discard all JS.
saveOptions.ResourceHandlingOptions.JavaScript = Aspose.Html.Saving.ResourceHandling.Discard;
doc.Save(@"C:\outputFolder\index.html", saveOptions);
}
}
Also you can save all HTML files as a single MHTML file by using Aspose.Html.Saving.MHTMLSaveOptions
class.
using (Aspose.Html.Configuration config = new Aspose.Html.Configuration())
{
config.Security |= Aspose.Html.Sandbox.Scripts;
using (Aspose.Html.HTMLDocument doc = new Aspose.Html.HTMLDocument(@"C:\inputFolder\index.html", config))
{
Aspose.Html.Saving.MHTMLSaveOptions saveOptions = new Aspose.Html.Saving.MHTMLSaveOptions();
//This will disable depth filter, which will lead to saving of all referenced resources.
saveOptions.ResourceHandlingOptions.MaxHandlingDepth = -1;
//To handle only local resources user can set according URL restriction.
saveOptions.ResourceHandlingOptions.UrlRestriction = Aspose.Html.Saving.UrlRestriction.SameHost;
//This option is used to embed resources in to HTML files.
saveOptions.ResourceHandlingOptions.Default = Aspose.Html.Saving.ResourceHandling.Embed;
//This option is used to discard all JS.
saveOptions.ResourceHandlingOptions.JavaScript = Aspose.Html.Saving.ResourceHandling.Discard;
doc.Save(@"C:\outputFolder\index.mht", saveOptions);
}
}
As a result of this code, you will receive single MHTML
file which will contain three HTML pages. We hope this will be helpful. Please feel free to contact us if you need any further assistance.