URI rewriting

Use UriExportStrategy with CustomUriExportStrategy and IUriSavingHandler to rewrite resource URIs in the Markdown output. This is useful when images are served from a CDN or a different path than where they’re saved.

Note
URI rewriting works with file-based image strategies (ExportImagesToFileSystemStrategy or CustomImagesStrategy). It has no effect when images are embedded as Base64.

Prepend a CDN base URL

using GroupDocs.Markdown;

public class CdnUriHandler : IUriSavingHandler
{
    public void Handle(UriSavingArgs args)
    {
        args.SetResourceFileUri("https://cdn.example.com/assets/" + args.ResourceFileName);
    }
}

var options = new ConvertOptions
{
    ImageExportStrategy = new ExportImagesToFileSystemStrategy("output/images")
    {
        ImagesRelativePath = "images"
    },
    UriExportStrategy = new CustomUriExportStrategy(new CdnUriHandler())
};

MarkdownConverter.ToFile("business-plan.docx", "output/report.md", options);
// Images saved locally to output/images/
// Markdown references: ![](https://cdn.example.com/assets/img-001.png)

business-plan.docx is a sample file used in this example. Click here to download it.

output/images/img-001.png (4 KB)
output/images/img-002.jpg (41 KB)
output/images/img-003.png (14 KB)
output/report.md (5 KB)

Download full output

UriSavingArgs properties

PropertyDescription
ResourceFileNameDefault file name generated by the library
ResourceFileUriDefault URI that would appear in the Markdown
SetResourceFileUri(string)Override the URI written to the Markdown output
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.