MarkdownToImageLibrary 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MarkdownToImageLibrary --version 1.1.0
                    
NuGet\Install-Package MarkdownToImageLibrary -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MarkdownToImageLibrary" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MarkdownToImageLibrary" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MarkdownToImageLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MarkdownToImageLibrary --version 1.1.0
                    
#r "nuget: MarkdownToImageLibrary, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MarkdownToImageLibrary@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MarkdownToImageLibrary&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MarkdownToImageLibrary&version=1.1.0
                    
Install as a Cake Tool

Markdown to Image Converter

A .NET application that processes markdown files to extract HTML/CSS sections and converts them to images using wkhtmltoimage.exe.

Features

  • Extracts HTML sections from markdown files (content within html blocks)
  • Converts each HTML section to a PNG image using wkhtmltoimage
  • Handles CSS styles embedded within HTML sections
  • Creates complete HTML documents with proper structure
  • Saves generated images in an images folder
  • Supports multiple HTML sections per markdown file

Prerequisites

  1. .NET 8.0 SDK - Download from https://dotnet.microsoft.com/download
  2. wkhtmltoimage - Download from https://wkhtmltopdf.org/downloads.html

Installing wkhtmltoimage

  1. Download the wkhtmltopdf installer for Windows
  2. Install it (default location: C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe)
  3. Optionally add the installation directory to your PATH environment variable

Build and Run

  1. Restore dependencies:

    dotnet restore
    
  2. Build the application:

    dotnet build
    
  3. Run the application:

    dotnet run --project MarkdownToImageConverter.csproj sample.md
    

    Or specify the path to wkhtmltoimage.exe if it's not in PATH:

    dotnet run --project MarkdownToImageConverter.csproj sample.md "C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
    
  4. Check system status:

    dotnet run --project MarkdownToImageConverter.csproj --check
    

Usage

MarkdownToImageConverter <markdown-file-path> [wkhtmltoimage-path]
MarkdownToImageConverter --check

Examples

# Check system status
dotnet run --project MarkdownToImageConverter.csproj --check

# Using wkhtmltoimage from PATH
dotnet run --project MarkdownToImageConverter.csproj example.md

# Specifying wkhtmltoimage path
dotnet run --project MarkdownToImageConverter.csproj example.md "C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"

Input Format

The application looks for HTML sections in markdown files marked with html code blocks:

# My Document

Some regular markdown content...

## HTML Section

```html
<style>
    .my-class {
        color: blue;
        font-family: Arial;
    }
</style>
<div class="my-class">
    <h1>Hello World</h1>
    <p>This will be converted to an image!</p>
</div>
\```

More markdown content...

Output

  • Images are saved in the images folder
  • Each HTML section becomes a separate PNG file
  • Files are named: {markdown-filename}_section_{number}.png
  • Example: sample_section_1.png, sample_section_2.png

How It Works

  1. Parse Markdown: Reads the markdown file and extracts all html blocks
  2. Process HTML: Creates complete HTML documents with proper structure
  3. Extract Styles: Separates CSS styles and HTML content
  4. Generate Images: Uses wkhtmltoimage to render HTML to PNG images
  5. Save Results: Outputs images to the images folder

Dependencies

  • Markdig: For markdown processing
  • HtmlAgilityPack: For HTML parsing and manipulation
  • wkhtmltoimage: External tool for HTML to image conversion

Error Handling

The application handles various error conditions:

  • Missing markdown files
  • Invalid HTML content
  • wkhtmltoimage execution failures
  • File system errors

Sample File

A sample.md file is included that demonstrates the expected input format with working HTML/CSS examples.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 222 8/6/2025
1.1.0 215 8/6/2025
1.0.2 218 8/6/2025