Skip loading of external resources

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Conversion MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-conversion -- dnx GroupDocs.Conversion.Mcp --yes
Folders, licensing and more →

What are external resources?

External resources refer to various types of content or files that are not directly embedded within the document but are instead referenced and loaded from external locations. These resources enhance the functionality, appearance, and interactivity of the document. Common external resources include images, audio, video, fonts, CSS, scripts, frameworks, and so on. GroupDocs.Conversion considers external any resource that a document is trying to load from an external URL.

Utilizing external resources optimizes the performance, maintainability, and scalability of web pages and other documents. These resources are typically cached by browsers, which can reduce the load time of subsequent visits to a website. However, relying too heavily on external resources can also introduce dependencies and potential points of failure if the external sources become unavailable.

Restricting all external resources

While loading web, presentations and word-processing documents, the GroupDocs.Conversion allows skipping of loading the external resources.

To restrict the loading of external resources during the conversion, use the getSkipExternalResources() boolean property of the respective WebLoadOptions, PresentationLoadOptions, or WordProcessingLoadOptions class.

The following code snippet shows how to skip loading of external resources while loading an HTML document:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.WebLoadOptions;

public static void skipExternalResources()
{
    String outputFile = "skip_external_resources.pdf";

    WebLoadOptions loadOptions =  new WebLoadOptions();
    loadOptions.setSkipExternalResources(true);

    Converter converter = new Converter("groupdocs.html", ()-> loadOptions);

    PdfConvertOptions options = new PdfConvertOptions();
    converter.convert(outputFile, options);
}

public static void main(String[] args){
    skipExternalResources();
}

groupdocs.html is sample file used in this example. Click here to download it.

skip_external_resources.pdf is converted PDF document. Click here to download it.

Allowlisting some of the external resources

Sometimes you may want to skip loading most of the external resources, but still load some particular resources. To allow-list specific resources during the conversion, use the WhitelistedResources property of the respective WebLoadOptions, PresentationLoadOptions, or WordProcessingLoadOptions class. The property is effective when the SkipExternalResources property is enabled. The WhitelistedResources property accepts the string list containing the portions of URLs to be loaded while restricting the loading of other external resources.

The following code snippet shows how to load the JPG and JPEG images and any resources from the example.com domain while restricting any other external resources:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.WebLoadOptions;
import java.util.Arrays;

public static void setWhitelistedResources()
{
    String outputFile = "whitelisted_resources.pdf";

    WebLoadOptions loadOptions =  new WebLoadOptions();
    loadOptions.setSkipExternalResources(true);
    loadOptions.setWhitelistedResources(Arrays.asList( "jpeg", "via.placeholder.com" ));

    Converter converter = new Converter("groupdocs.html", ()-> loadOptions);

    PdfConvertOptions options = new PdfConvertOptions();
    converter.convert(outputFile, options);
}

public static void main(String[] args){
    setWhitelistedResources();
}

groupdocs.html is sample file used in this example. Click here to download it.

whitelisted_resources.pdf is converted PDF document. Click here to download it.