---
title: "Overlay one PDF's graphics onto another"
canonical: https://www.graphicsmill.com/samples/Codecs/Pdf/OverlayPages_cs
product: "Graphics Mill"
source: "Codecs/Pdf/OverlayPages.cs"
---

# Overlay one PDF's graphics onto another

This sample shows how to overlay the vector content of one PDF file, such as a seal or logo, onto every page of another PDF file. It reads the stamp from "Seal.pdf" and the page content from "GraphicsContainer.pdf" with ` PdfReader `, shrinks the stamp's ` GraphicsContainer ` to a fixed size with ` Scale `, then draws the page content and the stamp together onto each output page with ` PdfWriter ` and ` Graphics.DrawContainer `.

## Instruction

Use the PDF API to overlay the graphics of one PDF file onto another: read both files' vector content with PdfReader, scale the overlay's GraphicsContainer to a fixed size, and draw the page content and the overlay together onto each output page with PdfWriter and Graphics.DrawContainer.

## Usings

```csharp
using System;
using System.Linq;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
const float stampSize = 90f; // Target size, in pixels, regardless of the stamp's native size.
const float margin = 20f;    // Distance from the page edge, in pixels.

using (var stampReader = new PdfReader("Seal.pdf"))
using (var stamp = stampReader.Frames[0].GetContent())
{
    var scale = stampSize / Math.Max(stamp.Width, stamp.Height);
    stamp.Scale(scale, scale);

    using (var contentReader = new PdfReader("GraphicsContainer.pdf"))
    using (var writer = new PdfWriter("OverlaidDocument.pdf"))
    using (var gr = writer.GetGraphics())
    {
        // The same stamp container is drawn onto every page of the content file.
        foreach (var frame in contentReader.Frames.Cast<PdfFrame>())
        {
            using (var pageContent = frame.GetContent())
            {
                writer.AddPage(pageContent.Width, pageContent.Height, pageContent.DpiX, pageContent.DpiY);

                // The original page content goes first, the stamp on top of it.
                gr.DrawContainer(pageContent, 0, 0);

                var stampX = pageContent.Width - stamp.Width - margin;
                var stampY = pageContent.Height - stamp.Height - margin;
                gr.DrawContainer(stamp, stampX, stampY);
            }
        }
    }
}
```

## Explanation

The code:

- Opens the stamp file "Seal.pdf" with ` PdfReader ` and gets its vector content as a ` GraphicsContainer `.
- Shrinks the stamp container to a fixed 90x90 pixel size with ` GraphicsContainer.Scale `, regardless of its native size.
- Opens the content file "GraphicsContainer.pdf" with a second ` PdfReader ` and iterates over its pages.
- For each page, adds a matching page to a ` PdfWriter ` and draws the original page content with ` Graphics.DrawContainer `.
- Draws the same scaled stamp container on top, positioned near the bottom-right corner.
- Produces one output PDF whose pages all carry the original content plus the overlaid stamp.

## Tags

- [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
- [Read](<https://www.graphicsmill.com/samples/tags/read_md>): Reading images with codecs
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Input

- [GraphicsContainer.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/GraphicsContainer_pdf>) (download)
- [Seal.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Seal_pdf>) (download)

## Output

- [OverlaidDocument.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/OverlaidDocument_pdf>) (download)
- [OverlaidDocument.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/OverlaidDocument_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.PdfFrame](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfFrame.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.Codecs.PdfWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.AddPage(Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_AddPage_4_37f6c741.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawContainer(GraphicsContainer,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawContainer_3_098aa7ce.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.Scale(Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_GraphicsContainer_Scale_2_427c5821.htm.md>)
