C#/VB.NET: Convert PDF to Grayscale (Black and White)

Converting a PDF with color images to grayscale can help you reduce the file size and print the PDF in a more affordable mode without consuming colored ink. In this article, you will learn how to achieve the conversion programmatically in C# and VB.NET using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

  • Package Manager
PM> Install-Package Spire.PDF 

Convert PDF to Grayscale

The following are the steps to convert a color PDF to grayscale:

  • C#
  • VB.NET
using Spire.Pdf.Conversion;
 
namespace ConvertPdfToGrayscale
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfGrayConverter instance and load a PDF file
            PdfGrayConverter converter = new PdfGrayConverter(@"Sample.pdf");
            //Convert the PDF to grayscale
            converter.ToGrayPdf("Grayscale.pdf");
            converter.Dispose();
        }
    }
}
Imports Spire.Pdf.Conversion

Namespace ConvertPdfToGrayscale
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a PdfGrayConverter instance and load a PDF file
            Dim converter As PdfGrayConverter = New PdfGrayConverter("Sample.pdf")
            'Convert the PDF to grayscale
            converter.ToGrayPdf("Grayscale.pdf")
            converter.Dispose()
        End Sub
    End Class
End Namespace

The input PDF:

C#/VB.NET: Convert PDF to Grayscale (Black and White)

The output PDF:

C#/VB.NET: Convert PDF to Grayscale (Black and White)

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.