← Back to list

Convert Word to High-Quality Images in C# with DPI Control

Many developers often need to turn Word documents into images — whether it’s for displaying pages on a website, creating preview…

Alexander Stock · 2026-03-27 08:44 · 0 claps · 3.0 min read
#csharp #ms-word #png #image-to-word #high-quality
Open on Medium ↗

Convert Word to High-Quality Images in C# with DPI Control

Many developers often need to turn Word documents into images — whether it’s for displaying pages on a website, creating preview thumbnails, or producing crisp images for printing. The challenge is doing this without losing clarity, so the text and graphics remain sharp and professional-looking.

In this guide, we’ll show you how to convert Word documents to high-resolution PNG images in C#, using the Spire.Doc library.

Why DPI Matters in Word-to-Image Conversion

By default, converting Word pages to images often results in low-resolution output (typically around 96 DPI). This may appear acceptable on screen but can look blurry when:

  • Zooming in
  • Printing
  • Using the images in high-quality PDFs or slides

To fix this, we can control the DPI (dots per inch) during conversion. Higher DPI means more pixels per inch and sharper images. In this tutorial, we’ll use 300 DPI, which is perfect for printing.

Step 1: Install Spire.Doc

Before we start, make sure you have Spire.Doc for .NET installed. You can get it via NuGet:

Install-Package Spire.Doc

Step 2: Full C# Code for High-Resolution Conversion

Here’s a complete example of converting a Word document to high-resolution PNG images:

using Spire.Doc;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using Spire.Doc.Documents;

namespace ConvertWordToPng
{
    class Program
    {
        static void Main(string[] args)
        {
            // ==== Configurable parameters ====
            string inputFile = @"C:\Users\Administrator\Desktop\Input.docx";
            string outputFolder = @"C:\Users\Administrator\Desktop\Output";
            float targetDpi = 300; // Set your desired DPI here

            // Ensure the output folder exists
            Directory.CreateDirectory(outputFolder);

            // ==== Load the Word document ====
            Document doc = new Document();
            doc.LoadFromFile(inputFile);

            // ==== Convert each page to an image (Metafile) ====
            Image[] pageImages = doc.SaveToImages(ImageType.Metafile);

            // ==== Process each image ====
            for (int i = 0; i < pageImages.Length; i++)
            {
                Metafile pageMetafile = pageImages[i] as Metafile;

                // Convert to high-resolution bitmap
                Bitmap highResImage = ConvertToHighResolution(pageMetafile, targetDpi);

                // Build output file path
                string outputFile = Path.Combine(outputFolder, $"Image-{i + 1}.png");

                // Save as PNG
                highResImage.Save(outputFile, ImageFormat.Png);

                Console.WriteLine($"Saved: {outputFile}");
            }

            Console.WriteLine("Conversion completed!");
        }

        /// <summary>
        /// Convert a Metafile to a high-resolution Bitmap
        /// </summary>
        /// <param name="mf">Input Metafile</param>
        /// <param name="dpi">Target DPI</param>
        /// <returns>High-resolution Bitmap</returns>
        public static Bitmap ConvertToHighResolution(Metafile mf, float dpi)
        {
            // Calculate new pixel dimensions based on target DPI
            int width = (int)(mf.Width * dpi / mf.HorizontalResolution);
            int height = (int)(mf.Height * dpi / mf.VerticalResolution);

            // Create a new bitmap at target DPI
            Bitmap bmp = new Bitmap(width, height);
            bmp.SetResolution(dpi, dpi);

            // Draw the original Metafile onto the bitmap
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(mf, Point.Empty);
            }

            return bmp;
        }
    }
}

Output:

How the Code Works

  1. Load Word document
Document doc = new Document();
doc.LoadFromFile(inputFile);

This opens the .docx file for processing.

  1. Convert pages to Metafile images
Image[] pageImages = doc.SaveToImages(ImageType.Metafile);

Using Metafile ensures vector-quality graphics, which are ideal for high-resolution output.

  1. Resize images based on DPI
int width = (int)(mf.Width * dpi / mf.HorizontalResolution);
int height = (int)(mf.Height * dpi / mf.VerticalResolution);

The code calculates the correct pixel dimensions based on the target DPI, preserving sharpness.

  1. Draw high-resolution bitmap
using (Graphics g = Graphics.FromImage(bmp))
{
    g.DrawImage(mf, Point.Empty);
}
  1. Save as PNG

PNG is ideal for lossless quality, especially for text and diagrams.

Recommended DPI Settings

Tips and Best Practices

  • Always use a vector format (Metafile) before converting to bitmap. This avoids blurriness.
  • Adjust DPI based on usage — higher DPI = larger file size.
  • Use Path.Combine for file paths to avoid Windows path issues.
  • Batch processing is supported — all pages are converted automatically.
  • Change ImageFormat.Png to ImageFormat.Jpeg in the Save method if you want to convert Word to JPG instead of PNG.

Conclusion

With just a few lines of C# code and the power of Spire.Doc, you can convert Word documents into high-resolution images suitable for both web and print. Controlling the DPI ensures sharp text, crisp diagrams, and professional-quality output.

Before You Go…

Liked what you read? Show some love with a clap 👏 — it only takes a second but means a lot! Much appreciated!💙


메타데이터
post_id
19cfda0cfb06
slug
convert-word-to-high-quality-images-in-c-with-dpi-control-19cfda0cfb06
url
https://medium.com/@alexaae9/convert-word-to-high-quality-images-in-c-with-dpi-control-19cfda0cfb06
canonical_url
https://medium.com/@alexaae9/convert-word-to-high-quality-images-in-c-with-dpi-control-19cfda0cfb06
author_url
https://medium.com/@alexaae9
status
ok
fetched_at
2026-06-17 19:05:49