public class ImageSavingArgs
extends java.lang.Object
IImageSavingCallback.imageSaving(com.aspose.words.ImageSavingArgs) event.
To learn more, visit the Save a Document documentation article.
By default, when Aspose.Words saves a document to HTML, it saves each image into a separate file. Aspose.Words uses the document file name and a unique number to generate unique file name for each image found in the document.
ImageSavingArgs allows to redefine how image file names are generated or to completely circumvent saving of images into files by providing your own stream objects.
To apply your own logic for generating image file names use the getImageFileName() / setImageFileName(java.lang.String), getCurrentShape() and isImageAvailable() properties.
To save images into streams instead of files, use the P:Aspose.Words.Saving.ImageSavingArgs.ImageStream property.
| Modifier and Type | Method and Description |
|---|---|
ShapeBase |
getCurrentShape()
Gets the
ShapeBase object corresponding to the shape or group shape that is about to be saved. |
Document |
getDocument()
Gets the document object that is currently being saved.
|
java.lang.String |
getImageFileName()
Gets the file name (without path) where the image will be saved to.
|
java.io.OutputStream |
getImageStream() |
boolean |
getKeepImageStreamOpen()
Specifies whether Aspose.Words should keep the stream open or close it after saving an image.
|
boolean |
isImageAvailable()
Returns
true if the current image is available for export. |
void |
setImageFileName(java.lang.String value)
Sets the file name (without path) where the image will be saved to.
|
void |
setImageStream(java.io.OutputStream value) |
void |
setKeepImageStreamOpen(boolean value)
Specifies whether Aspose.Words should keep the stream open or close it after saving an image.
|
public Document getDocument()
public ShapeBase getCurrentShape()
ShapeBase object corresponding to the shape or group shape that is about to be saved.
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 ShapeBase.getShapeType() with ShapeType.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 getCurrentShape() property to generate a "better" file name by examining shape properties such as ImageData.getTitle() / ImageData.setTitle(java.lang.String)(Shape only), ImageData.getSourceFullName() / ImageData.setSourceFullName(java.lang.String) (Shape only) and ShapeBase.getName() / ShapeBase.setName(java.lang.String). 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.
ShapeBase object corresponding to the shape or group shape that is about to be saved.public boolean isImageAvailable()
true if the current image is available for export.
Some images in the document can be unavailable, for example, because the image is linked and the link is inaccessible or does not point to a valid image. In this case Aspose.Words exports an icon with a red cross. This property returns true if the original image is available; returns false if the original image is not available and a "no image" icon will be offered for save.
When saving a group shape or a shape that doesn't require any image this property is always true.
true if the current image is available for export.getCurrentShape()public java.lang.String getImageFileName()
This property allows you to redefine how the image file names are generated during export to HTML.
When the event is fired, this property contains the file name that was generated by Aspose.Words. You can change the value of this property to save the image into a different file. Note that file names must be unique.
Aspose.Words automatically generates a unique file name for every embedded image when exporting to HTML format. How the image file name is generated depends on whether you save the document to a file or to a stream.
When saving a document to a file, the generated image file name looks like
When saving a document to a stream, the generated image file name looks like Aspose.Words.
getImageFileName() / setImageFileName(java.lang.String) must contain only the file name without the path. Aspose.Words determines the path for saving and the value of the src attribute for writing to HTML using the document file name, the HtmlSaveOptions.getImagesFolder() / HtmlSaveOptions.setImagesFolder(java.lang.String) and HtmlSaveOptions.getImagesFolderAlias() / HtmlSaveOptions.setImagesFolderAlias(java.lang.String) properties.
getCurrentShape(),
isImageAvailable(),
HtmlSaveOptions.getImagesFolder(),
HtmlSaveOptions.setImagesFolder(java.lang.String),
HtmlSaveOptions.getImagesFolderAlias(),
HtmlSaveOptions.setImagesFolderAlias(java.lang.String)public void setImageFileName(java.lang.String value)
throws java.lang.Exception
This property allows you to redefine how the image file names are generated during export to HTML.
When the event is fired, this property contains the file name that was generated by Aspose.Words. You can change the value of this property to save the image into a different file. Note that file names must be unique.
Aspose.Words automatically generates a unique file name for every embedded image when exporting to HTML format. How the image file name is generated depends on whether you save the document to a file or to a stream.
When saving a document to a file, the generated image file name looks like
When saving a document to a stream, the generated image file name looks like Aspose.Words.
getImageFileName() / setImageFileName(java.lang.String) must contain only the file name without the path. Aspose.Words determines the path for saving and the value of the src attribute for writing to HTML using the document file name, the HtmlSaveOptions.getImagesFolder() / HtmlSaveOptions.setImagesFolder(java.lang.String) and HtmlSaveOptions.getImagesFolderAlias() / HtmlSaveOptions.setImagesFolderAlias(java.lang.String) properties.
value - The file name (without path) where the image will be saved to.java.lang.ExceptiongetCurrentShape(),
isImageAvailable(),
HtmlSaveOptions.getImagesFolder(),
HtmlSaveOptions.setImagesFolder(java.lang.String),
HtmlSaveOptions.getImagesFolderAlias(),
HtmlSaveOptions.setImagesFolderAlias(java.lang.String)public boolean getKeepImageStreamOpen()
Default is false and Aspose.Words will close the stream you provided in the P:Aspose.Words.Saving.ImageSavingArgs.ImageStream property after writing an image into it. Specify true to keep the stream open.
boolean value.public void setKeepImageStreamOpen(boolean value)
Default is false and Aspose.Words will close the stream you provided in the P:Aspose.Words.Saving.ImageSavingArgs.ImageStream property after writing an image into it. Specify true to keep the stream open.
value - The corresponding boolean value.public java.io.OutputStream getImageStream()
public void setImageStream(java.io.OutputStream value)