CustomImagesStrategy

CustomImagesStrategy class

Implements an image export strategy that user control how images are saved when a document is saved to Markdown format.

public class CustomImagesStrategy : IImageExportStrategy

Constructors

Name Description
CustomImagesStrategy(string, CustomImageSavingHandler) Initializes a new instance of the ExportImagesToFileSystemStrategy class.

Properties

Name Description
ImagesFolder { get; } Gets the folder where images will be exported.

Methods

Name Description
GetImageStream(ImageExportContext) Gets a stream for writing the exported image to the file system.

Other Members

Name Description
delegate CustomImageSavingHandler Delegate through which you can define the mechanism for saving images when creating a .md file

Examples

The following example shows how to use CustomImagesStrategy when converting a document:

// Set options
var options = new DocumentConverterOptions
{
    ImageExportStrategy = new CustomImagesStrategy(imageFolder, SetStreamHandler)
};

// Convert document without saving images
var markdown = MarkdownConverter.Convert("document.pdf", options);
// The markdown will contain image references like "file_0_originalName",
// but the actual image files won't be saved

// Set index
private int index = 0;

// Renaming function
private void RenameImageHandler(CustomImageSavingArgs args)
{
   args.SetOutputFileName($"file_{index}_{args.SuggestedFileName}");
   index++;
}

See Also