---
title: "Rasterize a PDF page two ways: quick vs. full control"
canonical: https://www.graphicsmill.com/samples/Codecs/Pdf/RasterizePdfTwoWays_cs
product: "Graphics Mill"
source: "Codecs/Pdf/RasterizePdfTwoWays.cs"
---

# Rasterize a PDF page two ways: quick vs. full control

This sample compares the two ways to turn a PDF page into a bitmap. ` PdfFrame.GetBitmap ` is the quickest option, but it always returns a 24-bit RGB bitmap at the page's own resolution. Getting the page's vector content with ` GetContent ` and rasterizing it separately with ` GraphicsContainerRasterizer ` is slower, since rendering goes through the vector content rather than a ready-made bitmap, but it allows any target pixel format and resolution, such as an alpha-capable format at a higher DPI than the source page.

## Instruction

Use the PDF API to compare two ways of rasterizing a PDF page: call PdfFrame.GetBitmap for a quick, fixed-format RGB24 bitmap, or get the page's vector content with GetContent and rasterize it with GraphicsContainerRasterizer for full control over the target pixel format and resolution.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
```

## Code Snippet

```csharp
using (var reader = new PdfReader("GraphicsContainer.pdf"))
{
    var frame = reader.Frames[0];

    // Quick: always 24-bit RGB, at the page's own resolution, with no control over
    // the output format -- but fast, since it comes straight from the frame.
    using (var quickBitmap = frame.GetBitmap())
    {
        quickBitmap.Save("RasterizedQuick.jpg");
    }

    // Full control: rendering the vector content separately is slower, but the target
    // pixel format and resolution are both configurable -- here, an alpha-capable format
    // at a higher resolution than the source page, which GetBitmap can't produce.
    using (var pageContent = frame.GetContent())
    {
        var rasterizer = new GraphicsContainerRasterizer(pageContent, PixelFormat.Format32bppArgb, RgbColor.Transparent)
        {
            TargetDpiX = 300f,
            TargetDpiY = 300f,
        };

        using (var customBitmap = rasterizer.Rasterize())
        {
            customBitmap.Save("RasterizedCustom.png");
        }
    }
}
```

## Explanation

The code:

- Opens "GraphicsContainer.pdf" with ` PdfReader ` and gets its first page as a ` PdfFrame `.
- Calls ` PdfFrame.GetBitmap ` for a quick RGB24 bitmap at the page's own resolution and saves it as "RasterizedQuick.jpg".
- Gets the same page's vector content as a ` GraphicsContainer ` with ` GetContent `.
- Creates a ` GraphicsContainerRasterizer ` targeting a 32-bit ARGB format with a transparent background, at a custom 300 DPI resolution set through ` TargetDpiX ` and ` TargetDpiY `.
- Calls ` Rasterize ` to render the container into a bitmap and saves it as "RasterizedCustom.png", preserving transparency and matching the requested resolution.

## Tags

- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Graphics Container](<https://www.graphicsmill.com/samples/tags/container_md>): Using graphics containers for grouped items
- [PDF](<https://www.graphicsmill.com/samples/tags/pdf_md>): Importing and exporting PDF documents
- [Thumbnail](<https://www.graphicsmill.com/samples/tags/thumbnail_md>): Generating thumbnails from images

## Input

- [GraphicsContainer.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/GraphicsContainer_pdf>) (download)

## Output

- [RasterizedQuick.jpg](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/RasterizedQuick_jpg>) (download)
- [RasterizedQuick.jpg](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/RasterizedQuick_jpg>) (preview)
- [RasterizedCustom.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/RasterizedCustom_png>) (download)
- [RasterizedCustom.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/RasterizedCustom_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.Frame.GetBitmap](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_Frame_GetBitmap.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfFrame.GetContent](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfFrame_GetContent.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfReader.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_PdfReader_Frames.htm.md>)
- [Aurigma.GraphicsMill.GraphicsContainerRasterizer](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GraphicsContainerRasterizer.htm.md>)
- [Aurigma.GraphicsMill.GraphicsContainerRasterizer.Rasterize](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_GraphicsContainerRasterizer_Rasterize.htm.md>)
- [Aurigma.GraphicsMill.GraphicsContainerRasterizer.TargetDpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_GraphicsContainerRasterizer_TargetDpiX.htm.md>)
- [Aurigma.GraphicsMill.GraphicsContainerRasterizer.TargetDpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_GraphicsContainerRasterizer_TargetDpiY.htm.md>)
