CurrentShape
ImageSavingArgs.CurrentShape property
Gets the ShapeBase
object corresponding to the shape or group shape that is about to be saved.
public ShapeBase CurrentShape { get; }
Remarks
IImageSavingCallback
can be fired while saving either a shape or a group shape. That’s why the property has ShapeBase
type. You can check whether it’s a group shape comparing ShapeType
with Group or by casting it to one of derived classes: Shape
or GroupShape
.
Aspose.Words uses the document file name and a unique number to generate unique file name for each image found in the document. You can use the CurrentShape
property to generate a “better” file name by examining shape properties such as Title
(Shape only), SourceFullName
(Shape only) and Name
. Of course you can build file names using any other properties or criteria but note that subsidiary file names must be unique within the export operation.
Some images in the document can be unavailable. To check image availability use the IsImageAvailable
property.
Examples
Shows how to involve an image saving callback in an HTML conversion process.
public void ImageSavingCallback()
{
Document doc = new Document(MyDir + "Rendering.docx");
// When we save the document to HTML, we can pass a SaveOptions object to designate a callback
// to customize the image saving process.
HtmlSaveOptions options = new HtmlSaveOptions();
options.ImageSavingCallback = new ImageShapePrinter();
doc.Save(ArtifactsDir + "HtmlSaveOptions.ImageSavingCallback.html", options);
}
/// <summary>
/// Prints the properties of each image as the saving process saves it to an image file in the local file system
/// during the exporting of a document to HTML.
/// </summary>
private class ImageShapePrinter : IImageSavingCallback
{
void IImageSavingCallback.ImageSaving(ImageSavingArgs args)
{
args.KeepImageStreamOpen = false;
Assert.True(args.IsImageAvailable);
Console.WriteLine($"{args.Document.OriginalFileName.Split('\\').Last()} Image #{++mImageCount}");
LayoutCollector layoutCollector = new LayoutCollector(args.Document);
Console.WriteLine($"\tOn page:\t{layoutCollector.GetStartPageIndex(args.CurrentShape)}");
Console.WriteLine($"\tDimensions:\t{args.CurrentShape.Bounds}");
Console.WriteLine($"\tAlignment:\t{args.CurrentShape.VerticalAlignment}");
Console.WriteLine($"\tWrap type:\t{args.CurrentShape.WrapType}");
Console.WriteLine($"Output filename:\t{args.ImageFileName}\n");
}
private int mImageCount;
}
See Also
- class ShapeBase
- class ImageSavingArgs
- namespace Aspose.Words.Saving
- assembly Aspose.Words