How to Generate Grayscale PDF Files in C#

In this tutorial, learn how to create grayscale PDFs using Iron PDF in C#. This process transforms colorful PDFs into classic black-and-white versions, akin to a vintage makeover. Begin by setting up a C# project in Visual Studio and ensure Iron PDF is installed via the NuGet package manager. In the Program.cs file, incorporate the Iron PDF library using the using IronPdf; directive. The core technique involves using ChromePdfRenderer, setting grayscale to true, and rendering a web address as a PDF. For demonstration, the Iron Software website is used. Post-rendering, the first page of the generated PDF is extracted with the copy page method and saved separately using the save as method, creating a file named test.pdf. Running the program results in a timeless grayscale PDF, ideal for reports or vintage-themed projects. The tutorial concludes with a prompt to like, subscribe, and explore Iron PDF's power via a provided link.

// This example demonstrates how to generate a grayscale PDF from a URL using IronPDF in C#.

// Add the IronPDF library to your project. Ensure IronPDF is installed via NuGet
// using the Package Manager Console:
// Install-Package IronPdf

using IronPdf; // Import the IronPdf namespace to access PDF generation classes

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of ChromePdfRenderer, which handles PDF rendering
        var renderer = new ChromePdfRenderer();

        // Set the renderer to render PDFs in grayscale
        renderer.RenderingOptions.Grayscale = true;

        // Render a PDF from a URL. In this case, the Iron Software website is used.
        var pdfDocument = renderer.RenderUrlAsPdf("https://ironsoftware.com");

        // Extract the first page of the rendered PDF document
        var firstPage = pdfDocument.ExtractPages(0, 1);

        // Save the extracted page as a new PDF file named 'test.pdf'
        firstPage.SaveAs("test.pdf");

        // Output a message indicating the PDF has been created
        Console.WriteLine("The grayscale PDF has been successfully created as 'test.pdf'.");
    }
}
// This example demonstrates how to generate a grayscale PDF from a URL using IronPDF in C#.

// Add the IronPDF library to your project. Ensure IronPDF is installed via NuGet
// using the Package Manager Console:
// Install-Package IronPdf

using IronPdf; // Import the IronPdf namespace to access PDF generation classes

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of ChromePdfRenderer, which handles PDF rendering
        var renderer = new ChromePdfRenderer();

        // Set the renderer to render PDFs in grayscale
        renderer.RenderingOptions.Grayscale = true;

        // Render a PDF from a URL. In this case, the Iron Software website is used.
        var pdfDocument = renderer.RenderUrlAsPdf("https://ironsoftware.com");

        // Extract the first page of the rendered PDF document
        var firstPage = pdfDocument.ExtractPages(0, 1);

        // Save the extracted page as a new PDF file named 'test.pdf'
        firstPage.SaveAs("test.pdf");

        // Output a message indicating the PDF has been created
        Console.WriteLine("The grayscale PDF has been successfully created as 'test.pdf'.");
    }
}
' This example demonstrates how to generate a grayscale PDF from a URL using IronPDF in C#.

' Add the IronPDF library to your project. Ensure IronPDF is installed via NuGet
' using the Package Manager Console:
' Install-Package IronPdf

Imports IronPdf ' Import the IronPdf namespace to access PDF generation classes

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Create an instance of ChromePdfRenderer, which handles PDF rendering
		Dim renderer = New ChromePdfRenderer()

		' Set the renderer to render PDFs in grayscale
		renderer.RenderingOptions.Grayscale = True

		' Render a PDF from a URL. In this case, the Iron Software website is used.
		Dim pdfDocument = renderer.RenderUrlAsPdf("https://ironsoftware.com")

		' Extract the first page of the rendered PDF document
		Dim firstPage = pdfDocument.ExtractPages(0, 1)

		' Save the extracted page as a new PDF file named 'test.pdf'
		firstPage.SaveAs("test.pdf")

		' Output a message indicating the PDF has been created
		Console.WriteLine("The grayscale PDF has been successfully created as 'test.pdf'.")
	End Sub
End Class
$vbLabelText   $csharpLabel

Further Reading: How to Generate PDF in Grayscale

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.
< PREVIOUS
How to Use Cookies with IronPDF for Secure PDF Generation in C#
NEXT >
How to Add PDF Bookmarks and Outlines in C# Using IronPDF