java.lang.Objectcom.aspose.words.ImageSavingArgs
public class ImageSavingArgs
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. To apply your own logic for generating image file names use the
To save images into streams instead of files, use the Example:
public void saveHtmlExportImages() throws Exception
{
Document doc = new Document(getMyDir() + "Document.doc");
// Create and pass the object which implements the handler methods.
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setImageSavingCallback(new HandleImageSaving());
doc.save(getMyDir() + "Document.SaveWithCustomImagesExport Out.html", options);
}
public class HandleImageSaving implements IImageSavingCallback
{
public void imageSaving(ImageSavingArgs e) throws Exception
{
// Change any images in the document being exported with the extension of "jpeg" to "jpg".
if (e.getImageFileName().endsWith(".jpeg"))
e.setImageFileName(e.getImageFileName().replace(".jpeg", ".jpg"));
}
}
Property Getters/Setters Summary | ||
---|---|---|
ShapeBase | getCurrentShape() | |
Gets the |
||
Document | getDocument() | |
Gets the document object that is currently being saved. | ||
java.lang.String | getImageFileName() | |
void | setImageFileName(java.lang.String value) | |
Gets or sets the file name (without path) where the image will be saved to. | ||
java.io.OutputStream | getImageStream() | |
void | setImageStream(java.io.OutputStream value) | |
Allows to specify the stream where the image will be saved to. | ||
boolean | isImageAvailable() | |
Returns true if the current image is available for export.
|
||
boolean | getKeepImageStreamOpen() | |
void | setKeepImageStreamOpen(boolean value) | |
Specifies whether Aspose.Words should keep the stream open or close it after saving an image. |
Property Getters/Setters Detail |
---|
getCurrentShape | |
public ShapeBase getCurrentShape() |
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
Some images in the document can be unavailable. To check image availability
use the
getDocument | |
public Document getDocument() |
getImageFileName/setImageFileName | |
public java.lang.String getImageFileName() / public void setImageFileName(java.lang.String value) |
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 <document base file name>.<image number>.<extension>.
When saving a document to a stream, the generated image file name looks like Aspose.Words.<document guid>.<image number>.<extension>.
src
attribute for writing
to HTML using the document file name, the
Example:
Shows how to define custom logic for controlling how images are saved when exporting to HTML based formats.public void saveHtmlExportImages() throws Exception { Document doc = new Document(getMyDir() + "Document.doc"); // Create and pass the object which implements the handler methods. HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML); options.setImageSavingCallback(new HandleImageSaving()); doc.save(getMyDir() + "Document.SaveWithCustomImagesExport Out.html", options); } public class HandleImageSaving implements IImageSavingCallback { public void imageSaving(ImageSavingArgs e) throws Exception { // Change any images in the document being exported with the extension of "jpeg" to "jpg". if (e.getImageFileName().endsWith(".jpeg")) e.setImageFileName(e.getImageFileName().replace(".jpeg", ".jpg")); } }
getImageStream/setImageStream | |
public java.io.OutputStream getImageStream() / public void setImageStream(java.io.OutputStream value) |
This property allows you to save images to streams instead of files during HTML.
The default value is null
. When this property is null
, the image
will be saved to a file specified in the
Using
isImageAvailable | |
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
.
getKeepImageStreamOpen/setKeepImageStreamOpen | |
public boolean getKeepImageStreamOpen() / public void setKeepImageStreamOpen(boolean value) |
Default is false
and Aspose.Words will close the stream you provided
in the true
to keep the stream open.