Background Color

When rasterizing a PDF using DynamicPDF Rasterizer, background color can be added with or without transparency.

Only colors supporting transparency are supported (see below).

PdfRasterizer.BackgroundColor

Use the PdfRasterizer class's BackgroundColor property to add a background color to a rasterized image. The following example illustrates adding background color (red without transparency.

PdfRasterizer rasterizer = new PdfRasterizer(pdfFilePath);
rasterizer.BackgroundColor = System.Drawing.Color.FromArgb(0, 255, 0, 0);
PngImageFormat pngImageFormat = new PngImageFormat(PngColorFormat.Rgb);
rasterizer.Draw(pngFilePath, pngImageFormat, ImageSize.Dpi72);         
Dim rasterizer As PdfRasterizer = New PdfRasterizer(pdfFilePath)
rasterizer.BackgroundColor = System.Drawing.Color.FromArgb(0, 255, 0, 0)
Dim pngImageFormat As PngImageFormat = New PngImageFormat(PngColorFormat.Rgb)
rasterizer.Draw(pngFilePath, pngImageFormat, ImageSize.Dpi72) 

Only color formats that support transparency are supported. For example, PngColorFormat.RgbA or TiffColorFormat.RgbA both support transparency.

Transparency

This example illustrates adding a red background color with transparency.

PdfRasterizer rasterizer = new PdfRasterizer(pdfFilePath);
rasterizer.BackgroundColor = System.Drawing.Color.FromArgb(150, 255, 0, 0);
PngImageFormat pngImageFormat = new PngImageFormat(PngColorFormat.RgbA);
DpiImageSize imagesize = new DpiImageSize(72.0f, 72.0f);
rasterizer.Draw(pngFilePath, pngImageFormat, ImageSize.Dpi72);       
Dim rasterizer As PdfRasterizer = New PdfRasterizer(pdfFilePath)
rasterizer.BackgroundColor = System.Drawing.Color.FromArgb(150, 255, 0, 0)
Dim pngImageFormat As PngImageFormat = New PngImageFormat(PngColorFormat.RgbA)
rasterizer.Draw(pdfFilePath.png, pngImageFormat, ImageSize.Dpi72)

In this topic