Loading of external resources containing by a document
Loading of external resources containing by a document
Leave feedback
If the document contains external resources, such as images, GroupDocs.Viewer loads them when rendering a document. This allows the document to display correctly, but is a potential security risk.
GroupDocs.Viewer allows you to manage loading of external resources contained by a document. These features are supported for the following formats:
Use the LoadOptions object to manage loading of external resources.
Skip loading of external resources
The following code snippet shows how to deny loading of external resources:
LoadOptionsloadOptions=newLoadOptions();loadOptions.setSkipExternalResources(true);// Skip loading of external resources
try(Viewerviewer=newViewer("business-flyer.docx",loadOptions)){HtmlViewOptionsviewOptions=HtmlViewOptions.forEmbeddedResources();viewer.view(viewOptions);}
valloadOptions=LoadOptions()loadOptions.isSkipExternalResources=true// Skip loading of external resources
Viewer("business-flyer.docx",loadOptions).use{viewer->valviewOptions=HtmlViewOptions.forEmbeddedResources()viewer.view(viewOptions)}
The following images show the output file with and without external resources (see top right corner):
loadOptions.setSkipExternalResources(false)
loadOptions.setSkipExternalResources(true)
Manage a safelist for loading external resources
The following code snippet shows how to allow loading of external resources from specific URLs:
LoadOptionsloadOptions=newLoadOptions();loadOptions.setSkipExternalResources(true);// Skip loading of all external resources
loadOptions.getWhitelistedResources().add("avatars.githubusercontent.com");// Enable loading of external resources that has `avatars.githubusercontent.com` fragment in resource URL.
try(Viewerviewer=newViewer("business-flyer.docx",loadOptions)){HtmlViewOptionsviewOptions=HtmlViewOptions.forEmbeddedResources();viewer.view(viewOptions);}
valloadOptions=LoadOptions()loadOptions.isSkipExternalResources=true// Skip loading of all external resources
loadOptions.whitelistedResources.add("avatars.githubusercontent.com")// Enable loading of external resources that has `avatars.githubusercontent.com` fragment in resource URL.
valviewer=Viewer("business-flyer.docx",loadOptions)valviewOptions=HtmlViewOptions.forEmbeddedResources()viewer.use{it.view(viewOptions)}
Set timeout for loading of external resources
The default timeout is 10 seconds. GroupDocs.Viewer allows you to change this value.
The following code snippet shows how to set a timeout to load external resources:
// Specify a timeout.
LoadOptionsloadOptions=newLoadOptions();loadOptions.setResourceLoadingTimeout(5000);// Render a file.
try(Viewerviewer=newViewer("sample.docx",loadOptions)){HtmlViewOptionsviewOptions=HtmlViewOptions.forEmbeddedResources();viewer.view(viewOptions);}
// Specify a timeout.
valloadOptions=LoadOptions()loadOptions.setResourceLoadingTimeout(5000)// Render a file.
Viewer("sample.docx",loadOptions).use{viewer->valviewOptions=HtmlViewOptions.forEmbeddedResources()viewer.view(viewOptions)}
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.