Prompt

How do I rotate and stamp PDFs in code?

Technology / Developer Tools2 observationsLast seen Oct 20, 2026

Latest observation

Oct 20, 2026OpenAI APIWeb search: off

You generally do this by using a PDF library that can:

  1. open the PDF
  2. rotate pages by changing page rotation or transforming content
  3. stamp content onto each page, such as text, images, or watermarks
  4. save the modified PDF

The exact code depends on the language and library. Here are common approaches.


Python example with PyMuPDF

PyMuPDF is very convenient for both rotating and stamping.

Install

pip install pymupdf

Rotate pages and add a stamp

import fitz  # PyMuPDF

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

for page in doc:
    # Rotate page 90 degrees clockwise
    page.set_rotation((page.rotation + 90) % 360)

    # Add a diagonal stamp-like text watermark
    rect = page.rect
    page.insert_text(
        (rect.width / 2 - 100, rect.height / 2),
        "APPROVED",
        fontsize=36,
        rotate=45,
        color=(1, 0, 0),
        overlay=True,
    )

doc.save("output.pdf")
doc.close()

Notes

  • set_rotation() changes the page rotation metadata.
  • insert_text(... rotate=45) adds a visible stamp/watermark.
  • overlay=True places the stamp on top of existing content.

Python example with ReportLab + PyPDF2

If you want to create a stamp separately and merge it onto pages, this is a common pattern.

Install

pip install pypdf reportlab

Code

from pypdf import PdfReader, PdfWriter
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from io import BytesIO

# Create a stamp PDF in memory
packet = BytesIO()
c = canvas.Canvas(packet, pagesize=letter)
c.setFont("Helvetica-Bold", 36)
c.setFillColorRGB(1, 0, 0)
c.saveState()
c.translate(300, 400)
c.rotate(45)
c.drawCentredString(0, 0, "APPROVED")
c.restoreState()
c.save()

packet.seek(0)
stamp_pdf = PdfReader(packet)

reader = PdfReader("input.pdf")
writer = PdfWriter()

for page in reader.pages:
    # Rotate page clockwise 90 degrees
    page.rotate(90)

    # Merge stamp
    page.merge_page(stamp_pdf.pages[0])

    writer.add_page(page)

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

Notes

  • page.rotate(90) rotates the page.
  • merge_page() stamps one PDF page onto another.

JavaScript / Node.js with pdf-lib

Install

npm install pdf-lib

Code

const fs = require('fs');
const { PDFDocument, rgb, StandardFonts, degrees } = require('pdf-lib');

async function main() {
  const pdfBytes = fs.readFileSync('input.pdf');
  const pdfDoc = await PDFDocument.load(pdfBytes);

  const font = await pdfDoc.embedFont(StandardFonts.HelveticaBold);

  const pages = pdfDoc.getPages();
  for (const page of pages) {
    // Rotate page
    const currentRotation = page.getRotation().angle;
    page.setRotation(degrees((currentRotation + 90) % 360));

    // Stamp text
    const { width, height } = page.getSize();
    page.drawText('APPROVED', {
      x: width / 2 - 100,
      y: height / 2,
      size: 36,
      font,
      color: rgb(1, 0, 0),
      rotate: degrees(45),
      opacity: 0.5,
    });
  }

  const out = await pdfDoc.save();
  fs.writeFileSync('output.pdf', out);
}

main();

C# example with iText 7

If you’re using .NET, iText is powerful for stamping and rotation.

using iText.Kernel.Pdf;
using iText.Kernel.Geom;
using iText.Layout;
using iText.Layout.Element;
using iText.Kernel.Colors;
using iText.Layout.Properties;

using var reader = new PdfReader("input.pdf");
using var writer = new PdfWriter("output.pdf");
using var pdf = new PdfDocument(reader, writer);

for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
    var page = pdf.GetPage(i);
    page.SetRotation((page.GetRotation() + 90) % 360);

    var canvas = new Canvas(new iText.Kernel.Pdf.Canvas.PdfCanvas(page), pdf, page.GetPageSize());
    canvas.ShowTextAligned(
        new Paragraph("APPROVED").SetFontSize(36).SetFontColor(ColorConstants.RED),
        page.GetPageSize().GetWidth() / 2,
        page.GetPageSize().GetHeight() / 2,
        i,
        TextAlignment.CENTER,
        VerticalAlignment.MIDDLE,
        45
    );
    canvas.Close();
}

Important distinction: rotate page vs rotate content

There are two different tasks:

  • Rotate page: changes how the viewer displays the page.
  • Rotate content: physically transforms the content stream.

Usually, for scanned documents or normal viewing, page rotation metadata is enough. For permanent transformation of what appears on the page, you may need to rotate the content itself.


Which library should you use?

  • Python: PyMuPDF is easiest for both stamping and rotation.
  • Node.js: pdf-lib is straightforward.
  • .NET: iText 7 is robust.
  • Need high-volume or complex PDF manipulation: consider commercial libraries or more advanced PDF toolkits.

If you want, I can give you:

  • a single-language solution for Python, JavaScript, Java, or C#
  • code that stamps an image watermark
  • code that rotates only specific pages
  • code that stamps the same PDF on every page

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.