ResourceLoadingAction Enumeration |
Specifies the mode of resource loading.
Namespace:
Aspose.Words.Loading
Assembly:
Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntaxpublic enum ResourceLoadingAction
Public Enumeration ResourceLoadingAction
public enum class ResourceLoadingAction
type ResourceLoadingAction
Members
| Member name | Value | Description |
---|
| Default | 0 |
Aspose.Words will load this resource as usual.
|
| Skip | 1 |
Aspose.Words will skip loading of this resource.
Only link without data will be stored for an image.
Css style sheet will be ignored.
|
| UserProvided | 2 |
Aspose.Words will use byte array provided by user in SetData(Byte) as resource data.
|
ExamplesShows how to process inserted resources differently.
public void ResourceLoadingCallback()
{
Document doc = new Document();
Assert.AreEqual(0, doc.GetChildNodes(NodeType.Shape, true).Count);
doc.ResourceLoadingCallback = new ImageNameHandler();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage("Google Logo");
builder.InsertImage("Aspose Logo");
builder.InsertImage("My Watermark");
Assert.AreEqual(3, doc.GetChildNodes(NodeType.Shape, true).Count);
doc.Save(ArtifactsDir + "DocumentBase.ResourceLoadingCallback.docx");
}
private class ImageNameHandler : IResourceLoadingCallback
{
public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
{
if (args.ResourceType == ResourceType.Image)
{
if (args.OriginalUri == "Google Logo")
{
using (WebClient webClient = new WebClient())
{
byte[] imageBytes =
webClient.DownloadData("http://www.google.com/images/logos/ps_logo2.png");
args.SetData(imageBytes);
return ResourceLoadingAction.UserProvided;
}
}
if (args.OriginalUri == "Aspose Logo")
{
using (WebClient webClient = new WebClient())
{
byte[] imageBytes = webClient.DownloadData(AsposeLogoUrl);
args.SetData(imageBytes);
return ResourceLoadingAction.UserProvided;
}
}
if (args.OriginalUri == "My Watermark")
{
System.Drawing.Image watermark = System.Drawing.Image.FromFile(ImageDir + "Transparent background logo.png");
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
byte[] imageBytes = (byte[])converter.ConvertTo(watermark, typeof(byte[]));
args.SetData(imageBytes);
return ResourceLoadingAction.UserProvided;
}
}
return ResourceLoadingAction.Default;
}
}
See Also