Use CustomImagesStrategy with the IImageSavingHandler interface for full control over how each image is saved during conversion. You can rename files, redirect output to a custom stream, or replace image content entirely.
Rename images with IImageSavingHandler
Implement IImageSavingHandler to customize saving logic for each image:
usingGroupDocs.Markdown;// Implement the IImageSavingHandler interfacepublicclassRenameHandler:IImageSavingHandler{privateint_index;publicvoidHandle(CustomImageSavingArgsargs){args.SetOutputImageFileName($"img_{_index}_{args.ImageFileName}");_index++;}}// Use the handler with CustomImagesStrategyvarhandler=newRenameHandler();varoptions=newConvertOptions{ImageExportStrategy=newCustomImagesStrategy("output/images",handler)};MarkdownConverter.ToFile("business-plan.docx","output/document.md",options);
business-plan.docx is a sample file used in this example. Click here to download it.
Use SetReplacementImage to substitute the original image with different content (e.g., a watermarked version or a placeholder):
usingSystem.IO;usingGroupDocs.Markdown;publicclassWatermarkHandler:IImageSavingHandler{publicvoidHandle(CustomImageSavingArgsargs){// Replace the original image with a custom placeholderStreamplaceholder=File.OpenRead("placeholder.png");args.SetReplacementImage(placeholder);args.SetOutputImageFileName("placeholder.png");}}varhandler=newWatermarkHandler();varoptions=newConvertOptions{ImageExportStrategy=newCustomImagesStrategy("output/images",handler)};MarkdownConverter.ToFile("business-plan.docx","output/document.md",options);
business-plan.docx is a sample file used in this example. Click here to download it.