Background Color
When rasterizing a PDF using DynamicPDF Rasterizer, background color can be added with or without transparency.
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)
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)