Converting PDF to grayscale allows people to print the PDF in a cheaper mode without consuming colored ink. In this article, I will illustrate how to convert a color PDF to grayscale easily with only 2 lines of code in C# and VB.NET using a free library – Free Spire.PDF for .NET.
Add Reference
You can either download Free Spire.PDF DLLs from this website or install Free Spire.PDF using NuGet Package Manager through the following steps:
- In your project’s Solution Explorer, right-click the project or “Dependencies” and select “Manage NuGet Packages”.
- Click “Browse” tab and search Free Spire.PDF.
- Install Free Spire.PDF.
Input PDF
Converted PDF
Convert PDF to Grayscale in C# and VB.NET
The PdfGrayConverter.ToGrayPdf(string) method is used for converting PDF to grayscale.
C# Code
The following example shows how to convert a PDF to grayscale in C# code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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(); } } } |
VB.NET Code
The following example shows how to convert a PDF to grayscale in VB.NET code.
1 2 3 4 5 6 7 8 9 10 11 | Imports Spire.Pdf.Conversion Namespace ConvertPdfToGrayscale Class Program Private Shared Sub Main( ByVal args As String ()) Dim converter As PdfGrayConverter = New PdfGrayConverter( "Sample.pdf" ) converter.ToGrayPdf( "Grayscale.pdf" ) converter.Dispose() End Sub End Class End Namespace |
That’s all. I hope it’s helpful for you. Happy coding!
Comments
Post a Comment