---
title: "Converting a PDF to a TIFF using color detection in C#"
canonical_url: "https://www.nutrient.io/guides/dotnet/samples/pdf-to-tiff-color-detection-cs/"
md_url: "https://www.nutrient.io/guides/dotnet/samples/pdf-to-tiff-color-detection-cs.md"
last_updated: "2026-05-14T21:57:26.872Z"
description: "Learn how to efficiently convert PDF documents to high-quality multipage TIFF files using a color detection plugin while minimizing file size."
---

# Converting a multipage PDF to a multipage TIFF using color detection in C#

This example shows how to convert an existing PDF document to a multipage TIFF file using the color detection plugin to produce the best quality output while keeping the output file size as low as possible.

[Get Started](https://www.nutrient.io/sdk/dotnet/getting-started.md)

[All Samples](https://www.nutrient.io/guides/dotnet/samples.md)

[Download](https://www.nutrient.io/guides/dotnet/downloads.md)

[Launch Demo](https://www.nutrient.io/demo/)

---

### C#

[C#](https://www.nutrient.io/guides/dotnet/samples/pdf-to-tiff-color-detection-cs.md)

### VB.NET

[VB.NET](https://www.nutrient.io/guides/dotnet/samples/pdf-to-tiff-color-detection-vbnet.md)

```cs

//We assume that GdPicture has been correctly installed and unlocked.
const string INPUT_DOCUMENT = "input.pdf";
const string OUTPUT_DOCUMENT = "output.tif";
const float DPI = 200F;
GdPicturePDF oGdPicturePDF = new GdPicturePDF();
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
if (oGdPicturePDF.LoadFromFile(INPUT_DOCUMENT, false) == GdPictureStatus.OK)
{
   int tiffID = 0;
   for (int i = 0; i < oGdPicturePDF.GetPageCount(); i++)
   {
	  oGdPicturePDF.SelectPage(i + 1);
	  //Rasterizing a page or extracting a page bitmap.
	  int rasterPage = oGdPicturePDF.RenderPageToGdPictureImageEx(DPI, true, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
	  if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
	  {
		 //Defining the compression of the tiff page. Let's use CCITT4 for bitonal pages and JPEG for others.
		 TiffCompression tiffCompression;
		 //Applying color detection and color depth automatic conversion.
		 oGdPictureImaging.ColorDetection(rasterPage, true, false, false);
		 if (oGdPictureImaging.GetBitDepth(rasterPage) == 1)
		 {
			tiffCompression = TiffCompression.TiffCompressionCCITT4;
		 }
		 else
		 {
			tiffCompression = TiffCompression.TiffCompressionJPEG;
		 }
		 if (i == 0)
		 {
			if (oGdPictureImaging.TiffSaveAsMultiPageFile(rasterPage, OUTPUT_DOCUMENT, tiffCompression) == GdPictureStatus.OK)
			{
			   //Firstly rasterized page's GdPicture ID becomes the multipage tiff id.
			   tiffID = rasterPage;
			}
			else
			{
			   MessageBox.Show("Error occurred when saving the file. Status: " + oGdPictureImaging.GetStat().ToString(), "Color Detection Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
			   break;
			}
		 }
		 else
		 {
			if (oGdPictureImaging.TiffAddToMultiPageFile(tiffID, rasterPage, tiffCompression)!= GdPictureStatus.OK)
			{
			   MessageBox.Show("Error occurred when adding a page. Status: " + oGdPictureImaging.GetStat().ToString(), "Color Detection Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
			   break;
			}
			oGdPictureImaging.ReleaseGdPictureImage(rasterPage);
		 }
	  }
	  else
	  {
		 MessageBox.Show("Error occurred when rendering the page. Status: " + oGdPicturePDF.GetStat().ToString(), "Color Detection Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
	  }
   }
   oGdPictureImaging.TiffCloseMultiPageFile(tiffID);
   oGdPictureImaging.ReleaseGdPictureImage(tiffID);
}
else
{
   MessageBox.Show("The file can't be opened. Status: " + oGdPicturePDF.GetStat().ToString(), "Color Detection Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
oGdPicturePDF.Dispose();
oGdPictureImaging.Dispose();

```

This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.

---

## Related pages

- [Automatically rotate pages of a multipage TIFF file using OCR and VB.NET](/guides/dotnet/samples/auto-rotate-tiff-vbnet.md)
- [Automatically rotate pages of a multipage TIFF file using OCR and C#](/guides/dotnet/samples/auto-rotate-tiff-cs.md)
- [Convert PDFs, MS Office, and images to TIFF in C#](/guides/dotnet/samples/convert-to-tiff-cs.md)
- [Saving images into folders based on their barcode](/guides/dotnet/samples/barcode-auto-sorting-cs.md)
- [Saving images into folders based on their barcode](/guides/dotnet/samples/barcode-auto-sorting-vbnet.md)
- [Generate a multipage TIFF file using a compression mode per page in C#](/guides/dotnet/samples/create-multipage-tiff-cs.md)
- [Converting a Microsoft Word binary file document (DOC) to a Microsoft Word OpenXML document (DOCX) in C#](/guides/dotnet/samples/doc-to-docx-cs.md)
- [Merging two PDF documents by alternating pages from both files in VB.NET](/guides/dotnet/samples/merge-pdf-alternate-pages-vbnet.md)
- [Using an external OCR engine during PDF/OCR generation](/guides/dotnet/samples/integrate-omnipage-ocr-cs.md)
- [Merging two PDF documents by alternating pages from both files in C#](/guides/dotnet/samples/merge-pdf-alternate-pages-cs.md)
- [Converting a multipage PDF to a multipage TIFF using color detection in VB.NET](/guides/dotnet/samples/pdf-to-tiff-color-detection-vbnet.md)
- [Recompress existing PDFs using MRC compression in C#](/guides/dotnet/samples/recompress-pdf-mrc-cs.md)
- [Recompress an existing PDF using color detection in VB.NET](/guides/dotnet/samples/recompress-pdf-vbnet.md)
- [Recompress an existing PDF using color detection in C#](/guides/dotnet/samples/recompress-pdf-cs.md)
- [Recompress existing PDFs using MRC compression in VB.NET](/guides/dotnet/samples/recompress-pdf-mrc-vbnet.md)
- [Highlight and crop an image in C#](/guides/dotnet/samples/select-image-crop-area-cs.md)
- [Highlight and crop an image in VB.NET](/guides/dotnet/samples/select-image-crop-area-vbnet.md)
- [Highlight a region in PDF or an image in VB.NET](/guides/dotnet/samples/select-pdf-image-region-vbnet.md)
- [Choosing the appropriate OCR zone in C#](/guides/dotnet/samples/select-ocr-zone-cs.md)
- [Highlight a region in a PDF or an image in C#](/guides/dotnet/samples/select-pdf-image-region-cs.md)
- [Choosing the appropriate OCR zone in VB.NET](/guides/dotnet/samples/select-ocr-zone-vbnet.md)
- [Save bitonal TIFFs with VB.NET using photometric 0](/guides/dotnet/samples/tiff-photometric-vbnet.md)
- [Convert a multipage TIFF to a multipage JBIG2 in VB.NET](/guides/dotnet/samples/tiff-to-jbig2-vbnet.md)
- [Save bitonal TIFF images with C# and CCITT4](/guides/dotnet/samples/tiff-photometric-cs.md)
- [Convert a multipage TIFF to a multipage JBIG2 in C#](/guides/dotnet/samples/tiff-to-jbig2-cs.md)

