Handles custom processing of images while saving to Markdown. Invoked once per image; mutate MarkdownImageSavingArgs to control the URI embedded in the Markdown output and/or redirect where the image bytes are written.
Called for each image being written to the Markdown document.
Examples
Scenario 1 — capture image bytes in memory and embed placeholder ids (useful when the caller wants to store images elsewhere or post-process them):
classCaptureImagesCallback:IMarkdownImageSavingCallback{privateint_index;privatereadonlyDictionary<string,MemoryStream>_images;publicCaptureImagesCallback(Dictionary<string,MemoryStream>images)=>_images=images;publicvoidImageSaving(MarkdownImageSavingArgsargs){varid=$"image{_index++}";varbuffer=newMemoryStream();_images[id]=buffer;args.ImageStream=buffer;// redirect image bytes into our bufferargs.ImageFileName=id;// placeholder URI written into the .mdargs.KeepImageStreamOpen=true;// keep buffer readable after Convert() returns}}varcaptured=newDictionary<string,MemoryStream>();try{varoptions=newWordProcessingConvertOptions{Format=WordProcessingFileType.Md};options.MarkdownOptions.ImageSavingCallback=newCaptureImagesCallback(captured);usingvarconverter=newConverter("source.pdf");converter.Convert("output.md",options);// captured["image0"], captured["image1"], ... now hold the image bytes}finally{foreach(varsincaptured.Values)s.Dispose();// caller owns the streams}
Scenario 2 — persist images to disk alongside the .md and reference them by file name:
classFileImagesCallback:IMarkdownImageSavingCallback{privatereadonlystring_outputFolder;privateint_index;publicFileImagesCallback(stringoutputFolder)=>_outputFolder=outputFolder;publicvoidImageSaving(MarkdownImageSavingArgsargs){varfileName=$"image{_index++}.png";args.ImageStream=newFileStream(Path.Combine(_outputFolder,fileName),FileMode.Create);args.ImageFileName=fileName;// written into the .md as // KeepImageStreamOpen left at default (false) → the converter flushes and closes the file.}}varoptions=newWordProcessingConvertOptions{Format=WordProcessingFileType.Md};options.MarkdownOptions.ImageSavingCallback=newFileImagesCallback("./out");usingvarconverter=newConverter("source.pdf");converter.Convert("./out/output.md",options);// ./out/image0.png, ./out/image1.png, ... are written and closed by the converter.