CustomImageSavingArgs

CustomImageSavingArgs class

Provides information and controls for saving a single image during document-to-Markdown conversion. An instance of this class is passed to the callback registered with CustomImagesStrategy for each image found in the source document.

public class CustomImageSavingArgs

Properties

Name Description
ImageFileName { get; } Gets the default file name (without path) suggested by the library for this image.
ImageFileNameOutput { get; } Gets the overridden file name set by SetOutputImageFileName, or null if no override was specified.
OutputDirectory { get; } Gets the output directory where images are being saved.
OutputStream { get; } Gets the custom output stream set by SetOutputStream, or null if no custom stream was specified.
ReplacementImageStream { get; } Gets the replacement image stream set by SetReplacementImage, or null if no replacement was specified.
ShapeType { get; } Gets the type of the shape that contains the image in the source document (for example, “Picture” or “Shape”).

Methods

Name Description
SetOutputImageFileName(string) Overrides the default file name for this image. The image will be saved under the specified name instead of the library-generated ImageFileName.
SetOutputStream(Stream) Redirects the image data to a custom writable stream instead of the default file output. The library will write the image bytes to this stream during conversion.
SetReplacementImage(Stream) Provides a replacement image to use instead of the original image from the source document. The stream must contain the complete replacement image data (e.g. PNG or JPEG bytes). When set, the library writes this data to the output instead of the original image.

Remarks

Use SetOutputImageFileName to change the file name the image is saved under, or SetOutputStream to redirect the image data to a custom stream. If neither method is called, the library uses the defaults provided by ImageFileName and OutputDirectory.

Examples

Renaming images in a custom callback:

var strategy = new CustomImagesStrategy(args =>
{
    // Change the output file name
    args.SetOutputImageFileName("thumb-" + args.ImageFileName);
});

var options = new ConvertOptions { ImageExportStrategy = strategy };

See Also