The following code sample shows how to handle loading of HTML external resources.
// Create an instance of ParserSettings to pass External Resource Handler
ParserSettingssettings=newParserSettings(newHandler());// Create an instance of Parser class to generate spreadsheet page previews
try(Parserparser=newParser(Constants.SampleHtmlWithImages,settings)){// Extract images from HTML document
Iterable<PageImageArea>images=parser.getImages();// Iterate over extracted images
for(PageImageAreai:images){// Print the type of image
System.out.println(i.getFileType());}}/**
* This class provides the ability to filter extracted images.
**/classHandlerextendsExternalResourceHandler{// Called before any external resource loads. It allows to skip unnecessary file loading.
@OverridepublicvoidonLoading(ExternalResourceLoadingArgsargs){// Check if the file name ends with installation.png
if(!args.getUri().endsWith("installation.png")){// Otherwise skip this file
args.setSkipped(true);}super.onLoading(args);}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: