I have big html file as STREAM with 100-200 images. And when i creating HtmlDocument from stream - i receive bad perfomance, because HtmlDocument loading each image.
How to disable loading of external resources ( image s) when creating an HTMLDocument from a stream.
An investigation ticket as HTMLNET-4343 has been logged in our issue tracking system to analyze feasibility of your requirements. We will surely look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.
We are sorry for the inconvenience.
Can you please clarify whether you need to completely disable the processing of images in the document, or only at the time the document is created? So that when rendering they are still loaded?
You can disable the loading of images using the configuration options:
internal class Program
{
private static string OutputDir = "c:\\temp\\";
static void Main(string[] args)
{
// Prepare HTML code and save it to a file
var code = "<span style=\"background-image:url('https://httpbin.org/image/jpeg')\">Hello World!!</span> " +
"<script>document.write('Have a nice day!');</script>";
File.WriteAllText(Path.Combine(OutputDir, "sandboxing.html"), code);
// Create an instance of Configuration
using (var configuration = new Configuration())
{
// Mark 'Images' as an untrusted resource
configuration.Security |= Sandbox.Images;
// Initialize an HTML document with specified configuration
using (var document = new HTMLDocument(Path.Combine(OutputDir, "sandboxing.html"), configuration))
{
// Convert HTML to PDF
Converter.ConvertHTML(document, new PdfSaveOptions(),
Path.Combine(OutputDir, "sandboxing_out.pdf"));
}
}
}
}
1 Like
The issues you have found earlier (filed as HTMLNET-4343) have been fixed in this update. This message was posted using Bugs notification tool by avpavlysh