GroupDocs.Parser for Java 23.2 Release Notes

Full List of Issues Covering all Changes in this Release

KeySummaryCategory
PARSERNET-1991Implement the ability to handle loading of external resourcesNew Feature

Public API and Backward Incompatible Changes

Implement the ability to handle loading of external resources

Description

This feature provides the ability to handle loading of HTML external resource.

Public API changes

ExternalResourceHandler public class was added

ExternalResourceLoadingArgs public class was added

ParserSettings public class was updated with changes as follows:

Usage

The following example shows how to handle loading of HTML external resource:

// Create an instance of ParserSettings to pass External Resource Handler
ParserSettings settings = new ParserSettings(new Handler());
// Create an instance of Parser class to generate spreadsheet page previews
try (Parser parser = new Parser(Constants.SampleHtmlWithImages, settings)) {
    // Extract images from HTML document
    Iterable<PageImageArea> images = parser.getImages();
    // Iterate over extracted images
    for (PageImageArea i : images) {
        // Print the type of image
        System.out.println(i.getFileType());
    }
}

/**
 * This class provides the ability to filter extracted images.
 **/
class Handler extends ExternalResourceHandler {
    // Called before any external resource loads. It allows to skip unnecessary file loading.
    @Override
    public void onLoading(ExternalResourceLoadingArgs args) {
        // 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);
    }
}