Background Color
When rasterizing a PDF using DynamicPDF Rasterizer, background color can be added with or without transparency.
info
A color must support transparency (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("DocumentA.pdf");
rasterizer.BackgroundColor = Color.FromArgb(150, 255, 0, 0);
PngImageFormat pngImageFormat = new PngImageFormat(PngColorFormat.RgbA);
DpiImageSize imagesize = new DpiImageSize(72.0f, 72.0f);
rasterizer.Draw("PngBackgroundImageWithRgbColor.png", 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)
[PngBackgroundImageWithRgbColor.cs](https://github.com/DynamicPDF/rasterizer-dotnet-core/blob/master/rasterizer-dotnet-examples-csharp/PngBackgroundImageWithRgbColor.cs){#gitlink-id target=_blank}
[PngBackgroundImageWithRgbColor.vb](https://github.com/DynamicPDF/rasterizer-dotnet-core/blob/master/rasterizer-dotnet-vb/PngBackgroundImageWithRgbColor.vb){#gitlink-id target=_blank}
Transparency
Only PngColorFormat.RgbA and TiffColorFormat.RgbA support transparency.. The following example illustrates adding a red background color with transparency when rasterizing a PDF to a PNG image.
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)
[PngBackgroundImageWithColorWithTransparency.cs](https://github.com/DynamicPDF/rasterizer-dotnet-core/blob/master/rasterizer-dotnet-examples-csharp/PngBackgroundImageWithColorWithTransparency.cs){#gitlink-id target=_blank}
[PgnBackgroundImageWithColorWithTransparency.vb](https://github.com/DynamicPDF/rasterizer-dotnet-core/blob/master/rasterizer-dotnet-vb/PgnBackgroundImageWithColorWithTransparency.vb){#gitlink-id target=_blank}