DEV Community

IronSoftware
IronSoftware

Posted on

Convert PDF to Grayscale in C# (.NET Guide)

Our print vendor charged 3x more for color pages. We generated colorful marketing PDFs but only needed black-and-white for physical distribution. Manual conversion in Acrobat was tedious for hundreds of files.

Grayscale conversion in C# automated the entire process. Here's how.

How Do I Generate Grayscale PDFs?

Set GrayScale rendering option when creating PDFs:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var renderer = new [ChromePdfRenderer](https://ironpdf.com/blog/videos/how-to-render-webgl-sites-to-pdf-in-csharp-ironpdf/)();
renderer.RenderingOptions.GrayScale = true;

var pdf = renderer.RenderHtmlAsPdf("<h1 style='color:red'>Red becomes gray</h1>");
pdf.SaveAs("grayscale.pdf");
Enter fullscreen mode Exit fullscreen mode

All colors convert to grayscale automatically.

Can I Convert Existing Color PDFs?

IronPDF's GrayScale option works only during generation, not for existing PDFs. For conversion of existing PDFs, use Ghostscript or third-party tools like Spire.PDF.

Workaround: Extract pages as images, convert to grayscale, rebuild PDF:

var pdf = PdfDocument.FromFile("color.pdf");
var images = pdf.RasterizeToImageFiles("page-*.png");

// Convert each image to grayscale (using System.Drawing or ImageSharp)
// Then rebuild PDF from grayscale images

var renderer = new ChromePdfRenderer();
// Combine grayscale images into new PDF
Enter fullscreen mode Exit fullscreen mode

This is lossy but works for basic needs.

Why Generate Grayscale PDFs?

Print cost savings: Color printing costs 2-5x more than black-and-white
File size: Grayscale PDFs are typically 30-50% smaller
Accessibility: Better contrast for some readers
Archival: Simpler for long-term storage

I generate grayscale versions of all printable marketing materials to reduce print costs.

Does Grayscale Affect Image Quality?

No quality loss for text and vector graphics. Photos lose color information but retain clarity.

Original: 5MB color PDF
Grayscale: 2MB grayscale PDF (same resolution)

How Do I Preview Grayscale Output?

Generate a test page:

var html = @"
<style>body { background: lightblue; }</style>
<h1 style='color:red'>Red Header</h1>
<p style='color:green'>Green text</p>
<img src='color-image.jpg' />";

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.GrayScale = true;

var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("preview.pdf");
Enter fullscreen mode Exit fullscreen mode

Open preview.pdf to verify color-to-gray conversion looks acceptable.

Can I Preserve Specific Colors?

No. GrayScale = true converts everything. Colors map to grayscale using luminance:

  • Yellow (bright) → Light gray
  • Blue (dark) → Dark gray
  • Red (mid) → Medium gray

If you need selective color preservation, don't use grayscale mode. Instead, adjust your HTML/CSS to use only specific colors.

How Do I Batch Convert Multiple Documents?

Loop through HTML files or templates:

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.GrayScale = true;

var files = Directory.GetFiles("templates", "*.html");

foreach (var file in files)
{
    var pdf = renderer.RenderHtmlFileAsPdf(file);
    var outputName = Path.GetFileNameWithoutExtension(file) + "-bw.pdf";
    pdf.SaveAs(outputName);
}
Enter fullscreen mode Exit fullscreen mode

I converted 200+ product sheets to grayscale for a trade show print run, saving $2,000 in printing costs.


Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.

Top comments (0)