Background Color
Background color can be added with or without transparency when rasterizing a PDF.
The example below illustrates how to add red background color without transparency.
PdfRasterizer rasterizer = new PdfRasterizer("DocumentA.pdf");
rasterizer.BackgroundColor = System.Drawing.Color.FromArgb(0, 255, 0, 0);
PngImageFormat pngImageFormat = new PngImageFormat(PngColorFormat.Rgb);
rasterizer.Draw("Output.png", pngImageFormat, ImageSize.Dpi72);
Dim rasterizer As PdfRasterizer = New PdfRasterizer("DocumentA.pdf")
rasterizer.BackgroundColor = System.Drawing.Color.FromArgb(0, 255, 0, 0)
Dim pngImageFormat As PngImageFormat = New PngImageFormat(PngColorFormat.Rgb)
rasterizer.Draw("Output.png", pngImageFormat, ImageSize.Dpi72)
The example below illustrates how to add red background color with transparency.
Note: Color format that supports transparency is required. For example, PngColorFormat.RgbA or TiffColorFormat.RgbA.
PdfRasterizer rasterizer = new PdfRasterizer("DocumentA.pdf");
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("Output.png", pngImageFormat, ImageSize.Dpi72);
Dim rasterizer As PdfRasterizer = New PdfRasterizer("DocumentA.pdf")
rasterizer.BackgroundColor = System.Drawing.Color.FromArgb(150, 255, 0, 0)
Dim pngImageFormat As PngImageFormat = New PngImageFormat(PngColorFormat.RgbA)
rasterizer.Draw("Output.png", pngImageFormat, ImageSize.Dpi72)