The following code sample shows how to handle loading of HTML external resources.
// Create an instance of ParserSettings to pass External Resource HandlerParserSettingssettings=newParserSettings(newHandler());// Create an instance of Parser class to generate spreadsheet page previewsusing(Parserparser=newParser(Constants.SampleHtmlWithImages,settings)){// Extract images from HTML documentIEnumerable<PageImageArea>images=parser.GetImages();// Iterate over extracted imagesforeach(PageImageAreaiinimages){// Print the type of imageConsole.WriteLine(i.FileType);}}/// <summary>/// This class provides the ability to filter extracted images./// </summary>privateclassHandler:ExternalResourceHandler{/// <summary>/// Called before any external resource loads. It allows to skip unnesesary file loading./// </summary>publicoverridevoidOnLoading(ExternalResourceLoadingArgsargs){// Check if the file name ends with installation.pngif(!args.Uri.EndsWith("installation.png")){// Otherwise skip this fileargs.Skipped=true;}base.OnLoading(args);}}
Warning
Loading of external resources is enabled by default, which means that parsing a document from an untrusted source may cause outbound HTTP requests to hosts named inside that document — for example remote images or stylesheets referenced by an HTML or MHTML file or by the HTML body of an email, linked images in Word processing documents, and INCLUDEPICTURE fields.
As of version 26.6.1, ExternalResourceHandler intercepts image extraction from HTML and MHTML only; other extraction methods and other formats do not route through it. To guarantee that no outbound request is made, block egress at the network or process level. See Network access and data privacy for the measured per-format behaviour.
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.