Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
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
Further Reading: How to Generate PDF in Grayscale