- C# Print document | Code Sample | Tall Components PDF C# samples
- Change colors of black-and-white TIFF after converting from PDF
- Convert multiple PDF pages to bitmap
- Convert PDF to an image using a dither matrix
- Convert PDF to JPG in C#
- Convert PDF to multipage TIFF in C# .NET
- Convert PDF to PNG using WPF
- Convert PDF to XPS
- Convert PDF with layers to image
- Display PDF in a WPF app and stay responsive - the code
- Font mapping
- PDF to grayscale TIFF C#
- C# Print PDF documents from a WPF application
- Render a PDF to bitmap
- Render PDF with ResolveFont event handler
- Render PDF to EMF
- Use multiple licenses
- How to use a system font for rendering text
Convert PDF to an image using a dither matrix
This code sample shows how to convert a PDF page to a bitmap image, while applying a dither matrix to the generated image. Dithering is the processing of applying a matrix to the original image and thereby adding seemingly randomized noise. This is done to prevent color banding and other large scale patterns to occur in your image. Read more.
using (FileStream fs = new FileStream(@"..\..\input.pdf", FileMode.Open, FileAccess.Read))
{
Document d = new Document(fs);
int[][] DitherMatrix = new int[][] {
new int[] { 9, 9, 7 },
new int[] { 4, 1, 0 },
new int[] { 0, 5, 2 }};
Page page = d.Pages[0];
Bitmap bitmap = new Bitmap((int)page.Width, (int)page.Height);
ConvertToTiffOptions options = new ConvertToTiffOptions();
//set a dithering matrix
options.DitherMatrix = DitherMatrix;
using (MemoryStream ms = new MemoryStream())
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.Clear(Color.White);
page.ConvertToTiff(ms, options);
}
bitmap = new Bitmap(ms, false);
bitmap.Save(@"..\..\output.bmp");
}
}