Background Color
When rasterizing a PDF using DynamicPDF Rasterizer, background color can be added with or without transparency. The following two examples illustrate, first without transparency and then with transparency.
This example illustrates adding a red background color 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)
This example illustrates adding a red background color with transparency.
NOTE: Only color formats that support transparency are supported. For example, PngColorFormat.RgbA or TiffColorFormat.RgbA both support 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)