Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To add a header or footer to every page of an existing PDF, create the header or footer as page content, then merge or insert it while iterating over the destination pages. pypdf is a good fit when your overlay is already a PDF page; PyMuPDF is convenient when you want to draw text or place an image at explicit coordinates. Both approaches preserve the original document and let you choose whether the new content appears above or below it.

Choose the right approach

Need Best approach How placement works
An overlay already designed as a PDF page pypdf Merge the stamp page onto each destination page; use a transformation for translation or scaling.
Text, logos or images positioned by coordinates PyMuPDF Insert text or an image into a rectangle on each page.
Foreground or background content Either Use over=True for content above existing artwork or over=False for an underlay.

Keep the header or footer inside each page’s media box and reserve enough margin that it does not cover body text. PDF coordinates are measured in points; a common print convention is 72 points per inch, but the existing document’s geometry—not an assumed paper size—should determine your coordinates.

Method 1: merge a prepared overlay with pypdf

Install the library

python -m pip install pypdf

Create a one-page file named header_footer.pdf. Its page should have the same intended page size as the input, with the header, footer, logo or page-number artwork in the correct locations. You can create that stamp with a PDF library, a design tool, or a template generated by your application.

Merge the overlay onto every page

from pypdf import PdfReader, PdfWriter

stamp = PdfReader("header_footer.pdf").pages[0]
reader = PdfReader("input.pdf")
writer = PdfWriter()

for page in reader.pages:
    page.merge_page(stamp, over=True)  # use over=False for an underlay
    writer.add_page(page)

with open("output.pdf", "wb") as out:
    writer.write(out)

merge_page() combines the stamp page’s content stream with the destination page. The same stamp can be reused for every page. With over=True, the header or footer is visible over existing content; with over=False, it becomes a background watermark and may be hidden by opaque page artwork.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
WavePad Audio Editing Software - Professional Audio and Music Editor for Anyone [Download]
  • Full-featured professional audio and music editor that lets you record and edit music, voice and other audio recordings
  • Add effects like echo, amplification, noise reduction, normalize, equalizer, envelope, reverb, echo, reverse and more
  • Supports all popular audio formats including, wav, mp3, vox, gsm, wma, real audio, au, aif, flac, ogg and more
  • Sound editing functions include cut, copy, paste, delete, insert, silence, auto-trim and more
  • Integrated VST plugin support gives professionals access to thousands of additional tools and effects

Move or resize the stamp

If the template is the wrong size or needs an offset, use merge_transformed_page() and a Transformation:

from pypdf import PdfReader, PdfWriter, Transformation

reader = PdfReader("input.pdf")
stamp = PdfReader("header_footer.pdf").pages[0]
writer = PdfWriter()

transform = (
    Transformation()
    .translate(tx=18, ty=0)
    .scale(sx=0.9, sy=0.9)
)

for page in reader.pages:
    page.merge_transformed_page(stamp, transform, over=True)
    writer.add_page(page)

with open("output.pdf", "wb") as out:
    writer.write(out)

Adjust tx and ty in points. Scaling around the page origin can move an element toward a corner, so inspect the result and alter the translation after scaling when necessary. To stamp only selected pages, iterate with enumerate(reader.pages) and call the merge only for the desired indices.

Handle rotated source pages

A page can have a rotation entry instead of physically rotated content. That can make an apparently correct overlay land in an unexpected position. For troublesome pages, normalize the page before merging:

from pypdf import PdfReader, PdfWriter

reader = PdfReader("input.pdf")
stamp = PdfReader("header_footer.pdf").pages[0]
writer = PdfWriter()

for page in reader.pages:
    if page.rotation:
        page.transfer_rotation_to_content()
    page.merge_page(stamp, over=True)
    writer.add_page(page)

with open("output.pdf", "wb") as out:
    writer.write(out)

Normalization changes the page’s content and geometry so subsequent placement uses a consistent orientation. Test portrait and landscape pages separately; a single stamp size is rarely appropriate for mixed page dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Method 2: insert text or images with PyMuPDF

Install and open the document

python -m pip install PyMuPDF

PyMuPDF exposes each page’s rectangle, allowing you to calculate a footer position from the actual width and height. The following writes text near the bottom while leaving a 12-point lower margin:

import pymupdf

doc = pymupdf.open("input.pdf")

for page in doc:
    margin = 36
    footer_rect = pymupdf.Rect(
        margin,
        page.rect.height - 36,
        page.rect.width - margin,
        page.rect.height - 12,
    )
    page.insert_textbox(
        footer_rect,
        "Confidential · 2026",
        fontsize=9,
        overlay=True,
    )

doc.save("output.pdf")

The rectangle’s coordinates are x0, y0, x1, y1. Calculate from page.rect rather than hard-coding a letter or A4 width, especially when the input contains mixed sizes. overlay=True places the text above existing content; set it to False for an underlay. Check the return value of insert_textbox() in your installed version when you need to detect text that did not fit.

Add a logo or other image

For an image header, use a small rectangle inside the page bounds. The PyMuPDF basics documentation demonstrates page.insert_image(page.bound(), filename="watermark.png", overlay=False); a logo normally belongs in a much smaller rectangle:

import pymupdf

doc = pymupdf.open("input.pdf")
logo = "logo.png"

for page in doc:
    rect = pymupdf.Rect(36, 18, 86, 68)
    page.insert_image(rect, filename=logo, overlay=True)

doc.save("output.pdf")

For a footer image, derive the rectangle from page.rect.height, for example pymupdf.Rect(36, page.rect.height - 54, 86, page.rect.height - 18). Keep the rectangle within the page and scale the source image to avoid covering body text.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reuse image data for large documents

When inserting the same logo repeatedly, read its bytes once and pass the data to the insertion call where supported by your PyMuPDF version. Reusing image data avoids needless file reads and can reduce avoidable memory and file-size overhead. Confirm the exact keyword signature against the version installed in your deployment.

Page numbers and per-page text

A single static stamp cannot automatically know the destination page number. Generate a stamp for each page, or use a coordinate-based API and calculate the label during iteration:

import pymupdf

doc = pymupdf.open("input.pdf")
total = len(doc)

for number, page in enumerate(doc, start=1):
    rect = pymupdf.Rect(36, page.rect.height - 36, page.rect.width - 36, page.rect.height - 12)
    page.insert_textbox(
        rect,
        f"Page {number} of {total}",
        fontsize=9,
        align=pymupdf.TEXT_ALIGN_CENTER,
        overlay=True,
    )

doc.save("numbered.pdf")

For pypdf, create a separate one-page stamp containing each page’s number, then merge the matching stamp while iterating. This is useful when the footer includes complex PDF artwork, but it requires generating or caching those stamp pages.

Preservation, output, and security considerations

  • Preservation: merging adds content; it does not reflow paragraphs or reserve margin automatically. If the original text reaches the edge, move the overlay or regenerate the source with a larger margin.
  • Forms and annotations: verify interactive fields, links and annotations after writing. A visual overlay is separate from form-field values and does not replace them.
  • Encrypted files: decrypt with the permitted password before editing. Do not bypass access controls; honor the document owner’s permissions.
  • Fonts and transparency: embed fonts in generated stamp PDFs when portability matters, and test transparent PNGs against both light and dark page backgrounds.
  • Atomic writes: write to a temporary output and replace the final file only after the writer closes successfully, so a failed run does not destroy the input.
  • Validation: reopen the output, count pages, and inspect portrait, landscape, rotated and unusually sized pages before distributing it.

Troubleshooting

The header is invisible

Check that the stamp is inside the destination page’s bounds, that the merge uses over=True, and that the stamp’s color or transparency contrasts with the page. An underlay can be hidden by an opaque background.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The footer covers body text

Move it farther from the content area, reduce its rectangle or font size, or regenerate the source PDF with a reserved bottom margin. Neither library can infer where the document’s meaningful text ends.

Content is shifted on rotated pages

Inspect page.rotation. With pypdf, call transfer_rotation_to_content() before merging and then test each orientation. With PyMuPDF, calculate from the page’s exposed rectangle rather than assuming the original orientation.

Text does not fit in a PyMuPDF rectangle

Increase the rectangle height, reduce the font size, shorten the string or use a larger margin. Treat a negative or otherwise unsuccessful insertion result as a layout error instead of silently shipping a clipped footer.

Rank #4
MixPad Free Multitrack Recording Studio and Music Mixing Software [Download]
  • Create a mix using audio, music and voice tracks and recordings.
  • Customize your tracks with amazing effects and helpful editing tools.
  • Use tools like the Beat Maker and Midi Creator.
  • Work efficiently by using Bookmarks and tools like Effect Chain, which allow you to apply multiple effects at a time
  • Use one of the many other NCH multimedia applications that are integrated with MixPad.

The output file is unexpectedly large

Do not recreate or embed a separate high-resolution image for every page. Reuse image data, use an appropriately sized logo and avoid rasterizing the entire PDF when only a small overlay is needed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The PDF opens but looks different in another viewer

Open the result in at least two PDF viewers and inspect transparency, fonts, links and annotations. PDF rendering differences are often exposed by unusual blend modes, missing fonts or nonstandard page boxes.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your workflow starts with a web page and the real goal is a PDF or image of that page, ScreenshotNeo can capture it with one request instead of maintaining browser automation. Before capture it accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status.

For a PDF capture, use the API’s PDF options for paper size, margins, orientation and page ranges. The service also supports custom CSS and JavaScript, waiting for a selector, delay or network idle, custom headers and cookies, authentication, timezone and geolocation, and signed asynchronous webhooks. An MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.

See the ScreenshotNeo documentation for the current parameters. A basic request is:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

There is a free allowance of 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is included on every plan. Create a free ScreenshotNeo account.

Best Value
Corel PDF Fusion Software
  • Save money by using PDF Fusion to view over 100 file formats without having to purchase additional software
  • Merge incompatible files quickly and easily by dragging and dropping in PDF Fusion to create a new PDF documents
  • Save time with PDF Fusion's editing tools to reuse the content from existing documents without starting from scratch

FAQ

Can I add a header without rebuilding the PDF?

Yes. Prepare a one-page overlay and merge it with pypdf, or insert text and images directly with PyMuPDF. The original page content remains in place.

Should I use a stamp or a watermark?

Use a foreground stamp for a readable header or footer. Use an underlay when the new content should sit behind existing artwork; choose over=False in the relevant operation.

Do all pages need the same overlay size?

No. Mixed page sizes and rotations often need page-specific coordinates or stamps. Calculate positions from each page’s geometry.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can I add a header without rebuilding the PDF?

Yes. Prepare a one-page overlay and merge it with pypdf, or insert text and images directly with PyMuPDF.

Should I use a stamp or a watermark?

Use foreground content for a readable header or footer; use an underlay when it should sit behind existing artwork.

Do all pages need the same overlay size?

No. Mixed page sizes and rotations often require page-specific coordinates or stamps.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.