Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer


Generate Grayscale PDF Example

To generate a grayscale PDF, you can set the GrayScale property of the RenderingOptions to true.

In the provided code snippet, we see that the grayscale feature is enabled after instantiating a ChromePdfRenderer. It is then used to render a web page using the RenderUrlAsPdf method. The code snippet also includes extracting only the first page of the rendered PDF and saving it locally.

:path=/static-assets/pdf/content-code-examples/how-to/color-grayscale-grayscale.cs
// Import IronPdf library, which enables PDF rendering and manipulation
using IronPdf;

// Create an instance of ChromePdfRenderer, which will handle PDF rendering
var renderer = new ChromePdfRenderer();

// Set the rendering options to generate a grayscale PDF
renderer.RenderingOptions.GrayScale = true;

// Render the specified URL as a PDF document,
// This will take the HTML content from the URL and convert it into a PDF format
var pdf = renderer.RenderUrlAsPdf("https://ironsoftware.com/");

// Save the first page of the PDF document as "test.pdf" file
// If the PDF has only one page, this will effectively save the entire PDF
pdf.SaveAs("test.pdf");
$vbLabelText   $csharpLabel

Please note
The current implementation of the Grayscale feature will turn the text in the rendered PDF document into an image, resulting in the ExtractAllImages method not outputting any text.

Currently, this functionality is only available when rendering PDFs. In the future, it would be beneficial to have the ability to convert existing PDF documents to grayscale.

Frequently Asked Questions

What is a grayscale PDF?

A grayscale PDF is a type of PDF document where all the colors and shades are represented using shades of gray instead of the full-color spectrum.

Why should I use grayscale PDFs?

Printing PDF documents in grayscale is cost-effective for large batch printing. It enhances readability, especially when the original colors are too bright or vibrant, and ensures consistent viewing across different systems.

How do I generate a grayscale PDF using IronPDF?

To generate a grayscale PDF using IronPDF, download the IronPDF Library, instantiate the ChromePdfRenderer class, set the GrayScale property of RenderingOptions to true, render the document, and export it.

Can I convert existing PDF documents to grayscale with IronPDF?

Currently, the functionality to convert existing PDFs to grayscale is not available. However, you can render new PDFs in grayscale.

How does IronPDF's grayscale rendering affect text extraction?

The current implementation of the Grayscale feature turns the text in the rendered PDF document into an image, which means the ExtractAllImages method will not output any text.

Is the grayscale rendering feature available for all PDF types?

The grayscale rendering feature is currently available only when rendering new PDFs, not for converting existing ones.

What are the steps to enable grayscale rendering in C# using IronPDF?

Instantiate the ChromePdfRenderer, set the GrayScale property of RenderingOptions to true, then render and save the PDF document.

Hairil Hasyimi Bin Omar
Hairil Hasyimi Bin Omar
Software Engineer
Like all great engineers, Hairil is an avid learner. He’s refining his knowledge of C#, Python, and Java, using that knowledge to add value to team members across Iron Software. Hairil joined the Iron Software team from Universiti Teknologi MARA in Malaysia, where he graduated with a Bachelor's degree in Chemical and Process Engineering.