Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
FREEDOM251

Freedom251 › Blog › document automation

How to Add Custom Text to PDF Files with Python

By Freedom251 Team · · 9 min read

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

Use PyMuPDF when you need to place text directly on an existing PDF page. Its Page.insert_text() method gives point-based placement, while Page.insert_textbox() wraps text inside a rectangle. If the text belongs on a brand-new page, use Document.insert_page(). For all three approaches, save to a new file and inspect the rendered result: text that does not fit a rectangle can be invisible without a warning, and PDF features are not universally guaranteed to survive every editing workflow.

Choose the PDF text method that matches the job

There are two fundamentally different tasks: overlaying text on a page that already exists, or creating a page whose main content is your text. PyMuPDF covers both. A separate ReportLab-and-pypdf workflow is useful when you want to draw a page independently and then combine it with another PDF, but it requires careful coordinate and page-size alignment.

As an Amazon Associate I earn from qualifying purchases.

Goal Documented option Main controls Important check
Place a label, note, page number, or watermark at a known point Page.insert_text() Start point, font, size, color, rotation, and foreground/background overlay Control the number of lines so text does not run beyond the page height
Put paragraphs or labels inside a bounded area Page.insert_textbox() Rectangle dimensions, wrapping, alignment, font, size, color, rotation, and overlay Text that does not fit may be invisible without warning; validate the output
Add a page containing text Document.insert_page() Page position, width, height, text, font, size, and color Confirm the inserted page position and dimensions in the viewer
Draw a separate text page and combine PDFs ReportLab generation with pypdf merging Canvas coordinates, page dimensions, and merge position Coordinate systems, page sizes, and output preservation must be checked for the target document

Prepare a safe editing workflow

Work on a copy of the source PDF and write the result to a different filename. This keeps the original available if a rectangle is too small, a page index is wrong, or the output viewer exposes a layout problem. Before choosing coordinates, identify the page number and the visible area where the text must appear.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Confirm which page receives the text. PyMuPDF page indexes are zero-based, so the first page is accessed as doc[0].
  • Decide whether the text is a single line or a paragraph. Use point-based insertion for a controlled start point; use a rectangle for wrapping.
  • Choose a font, size, color, and rotation that remain legible against the existing page.
  • Decide whether the inserted text should be in front of or behind existing page content by setting the overlay behavior.
  • Save under a new name, then open or render the saved PDF in the viewer your recipients will use.

The documentation describes API behavior, not a universal compatibility guarantee for every PDF feature. A file with unusual page content or advanced features therefore deserves an explicit visual check after saving.

#1 Best Overall
Lenovo Idea Tab - College Tablet - 11″ 2.5K IPS Touchscreen Display - 90Hz - MediaTek Dimensity 6300-8 GB Memory - 256 GB Storage - Integrated Arm Mali-G57 MC2 - Tab Pen and Folio Case
  • POWER YOUR STUDY, FUEL YOUR PLAY – Discover smarter learning with the Lenovo Idea Tab. Stay campus-ready with all-day battery life, AI-powered apps to enhance your work, and sharp graphics for tv marathons with friends.
  • SMOOTH, POWERFUL, IMMERSIVE – The MediaTek Dimensity 6300 processor is more powerful than ever, with the AI-enhanced multitasking you need to stay ahead.
  • CIRCLE IT, SEARCH IT – Use your Lenovo Tab Pen or fingertip to circle items for instant search results or to translate other languages without switching apps. Circle to Search with Google ensures answers are only a circle away.
  • SHARP VIEW, CLEAR SOUND – Experience sharp visuals and immersive sound for study sessions and streaming breaks. With 72% NTSC and quad Dolby Atmos-tuned speakers you can enjoy your study breaks with vivid videos and crystal-clear sound.
  • LEVEL UP YOUR STUDY – Write, organize, sketch, and calculate with four learning apps built to match your flow. Lenovo AI Note, Squid, Nebo, and MyScript Calculator help you stay clear, focused, and ready for every study session.

Place a line of text on an existing page

Use Page.insert_text() for point-based placement

insert_text() starts at a supplied point and is suited to a short label, a signature note, a date, or a watermark whose position you already know. The point, font, size, color, rotation, and overlay settings are supplied in the call.

import fitz  # PyMuPDF

doc = fitz.open("input.pdf")
page = doc[0]

page.insert_text(
    (72, 72),
    "Approved for distribution",
    fontname="helv",
    fontsize=12,
    color=(0, 0, 0),
    rotate=0,
    overlay=True,
)

doc.save("output-with-label.pdf")
doc.close()

The coordinates are PDF points measured from the page’s upper-left placement convention used by this API. Start with a generous margin, then adjust after viewing the result. A line placed too close to an edge can be clipped by the page boundary or by the viewer’s display area.

Control multiple lines deliberately

Point-based insertion can write multiple lines, but the documented recipe emphasizes controlling the number of lines so they do not extend past the page height. If the content may grow, a rectangle is safer because it gives you a defined region to test. Do not assume surplus lines will be visible: lines beyond the usable page area are not written.

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

Wrap text inside a rectangle

Use Page.insert_textbox() for paragraphs and bounded labels

A textbox receives a rectangle and automatically wraps text to that rectangle’s width. This is the practical choice for a note beside a diagram, a boxed disclaimer, or a multi-line annotation.

Rank #2
Lenovo Idea Tab - College Tablet - 11″ 2.5K IPS Touchscreen Display - 90Hz - MediaTek Dimensity 6300-4 GB Memory - 128 GB Storage - Integrated Arm Mali-G57 MC2 - Tab Pen and Folio Case
  • POWER YOUR STUDY, FUEL YOUR PLAY – Discover smarter learning with the Lenovo Idea Tab. Stay campus-ready with all-day battery life, AI-powered apps to enhance your work, and sharp graphics for tv marathons with friends.
  • SMOOTH, POWERFUL, IMMERSIVE – The MediaTek Dimensity 6300 processor is more powerful than ever, with the AI-enhanced multitasking you need to stay ahead.
  • CIRCLE IT, SEARCH IT – Use your Lenovo Tab Pen or fingertip to circle items for instant search results or to translate other languages without switching apps. Circle to Search with Google ensures answers are only a circle away.
  • SHARP VIEW, CLEAR SOUND – Experience sharp visuals and immersive sound for study sessions and streaming breaks. With 72% NTSC and quad Dolby Atmos-tuned speakers you can enjoy your study breaks with vivid videos and crystal-clear sound.
  • LEVEL UP YOUR STUDY – Write, organize, sketch, and calculate with four learning apps built to match your flow. Lenovo AI Note, Squid, Nebo, and MyScript Calculator help you stay clear, focused, and ready for every study session.
import fitz

doc = fitz.open("input.pdf")
page = doc[0]

box = fitz.Rect(72, 100, 300, 170)
page.insert_textbox(
    box,
    "This paragraph is constrained to the selected rectangle.",
    fontname="helv",
    fontsize=11,
    color=(0, 0, 0),
    align=0,
    rotate=0,
    overlay=True,
)

doc.save("output-with-note.pdf")
doc.close()

Choose the rectangle from the content’s real dimensions, not merely from the location where its first line should begin. A narrow box forces more wrapping; a short box leaves less vertical room. The API warning is important: portions that do not fit can be invisible without warning. If a sentence disappears, enlarge the rectangle, reduce the font size, shorten the text, or split the content into separate boxes.

Use alignment, rotation, and layering intentionally

The textbox API exposes alignment as well as rotation. Use alignment when the text must be centered or otherwise positioned inside the rectangle, and use rotation for labels that follow a page edge or diagram. The overlay setting controls whether the inserted text is placed in the foreground or background. Foreground placement is appropriate when the annotation must remain readable over existing artwork; background placement can put a watermark behind page content.

Add a new page containing text

Use Document.insert_page() instead of overlaying an existing page

When the requirement is “add a page,” do not force the text into an existing page’s coordinates. insert_page() creates a page at the requested position and accepts text, font size, page width and height, font name, and color.

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

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

new_page_index = doc.insert_page(
    pno=-1,
    text="Appendix: processing notes",
    fontsize=14,
    width=595,
    height=842,
    fontname="helv",
    color=(0, 0, 0),
)

print("New page index:", new_page_index)
doc.save("output-with-new-page.pdf")
doc.close()

Using pno=-1 places the new page at the end. Supply another page position when the page must appear earlier in the document. The documented default starting location for inserted text is 50 points from the left and 72 points from the top. Set the page width and height to the dimensions required by the document rather than assuming every source uses the same size.

Rank #3
Android Tablet 10 Inch Tablet With Case Stylus Android 15 Tablets 8GB RAM 32GB ROM Support 1TB Expansion 6000mah Battery 10.1" IPS HD Touchscreen 2MP+8MP Dual Camera WIFI-6 Bluetooth5.0 Tablets
  • 【Multi-function Configuration】Android 15 portable tablet with stylus and foldable protective case. You can enter text directly using a stylus, easy response to various scenarios, making your work and study get twice the result with half the effort.
  • 【Android 15 Tablet】10 inch Tablet PC is equipped with the latest Android 15.0 system, built-in powerful Quad-core processor, 32GB ROM 8GB RAM(Including 5GB expansion), 1024GB expansion, support Wi-Fi, Bluetooth, GPS and more, enough memory allows you to store more favorite e-books, movies, music, pictures, videos, games
  • 【Broad Vision and Responsiveness】The Android tablet uses a 10.1 inch 1280*800 full HD IPS display, which can present a clearer picture effect and richer colors, bringing you a more realistic viewing experience, bringing you clearer and brighter Image. Equipped with 10.0-inch capacitive touch, five-point capacitive touch G+G, to ensure smoother motion in movies and games
  • 【Long Battery Life】 The Android tablets powered by a 6000mAh battery, can stand by 360 hours and continuous use up to 6-8 hours, easily charge via the 5V2A Type-C port. Super power and long battery life, say goodbye to the trouble of insufficient power and give you a full sense of security.
  • 【Coexistence of Beauty and Strength】 Our Android tablet equipped with a protective leather case. With a slim design, wear-resistant and resistant to falling, a delicate feel, unique texture, easy to carry, and more comfortable to hold with one hand. It's a good companion for your leisure and entertainment, as well as the best gift for various festivals and birthdays.

Build a separate text page with ReportLab and merge it with pypdf

A two-file workflow can be useful when the text page is generated independently of the source PDF. ReportLab’s pdfgen canvas draws strings at canvas coordinates; pypdf then combines the generated page with another PDF using page append or merge operations.

from reportlab.pdfgen import canvas
from pypdf import PdfReader, PdfWriter

width, height = 595, 842
canvas_out = canvas.Canvas("text-page.pdf", pagesize=(width, height))
canvas_out.setFont("Helvetica", 12)
canvas_out.drawString(72, height - 72, "Generated text page")
canvas_out.save()

source = PdfReader("input.pdf")
text_page = PdfReader("text-page.pdf").pages[0]
writer = PdfWriter()

for page in source.pages:
    writer.add_page(page)
writer.add_page(text_page)

with open("merged-output.pdf", "wb") as stream:
    writer.write(stream)

This example appends a complete page. An overlay variant uses the same building blocks but requires the generated page and target page to have matching dimensions and coordinates before a merge operation is applied. The documented building blocks do not establish a universal recipe for scale handling, rotation, or preservation of every source-PDF feature, so treat alignment and validation as part of the implementation rather than as automatic behavior.

When this workflow is the better fit

  • Use it when your text layout is already designed as an independent PDF page.
  • Use it when a reporting pipeline already generates pages with ReportLab and another stage owns PDF composition.
  • Prefer direct PyMuPDF insertion when you only need a label, note, or watermark on an existing page and want fewer moving parts.

Make coordinates and appearance predictable

Start with a visible margin

Pick a point or rectangle clearly inside the page, save a test copy, and adjust from the rendered result. A coordinate that looks correct in one page size may be misplaced on another. For a document with mixed page dimensions, calculate or inspect each target page rather than reusing one fixed rectangle blindly.

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

Choose presentation settings together

Font, size, color, and rotation interact with the available space. A larger font can make a textbox overflow; rotation changes the space the text occupies; a light color can disappear over a colored background. Set these properties in the same insertion call so the saved file records the intended appearance.

Rank #4
Samsung Galaxy Tab S10 Lite, 6GB RAM, 128GB, 2TB Expand, 10.9” LCD, Gray | Long Battery Life, S Pen for Note-Taking, Exynos 1380, Circle to Search, AI Tools
  • DIVE INTO THIS DISPLAY: All of your fun content pops on the 10.9" screen. Catch up on plans for the day while you cook breakfast, scroll your social feed in the evening or read an article in bed. Vision Booster adjusts the brightness to your environment
  • BATTERY FOR LONG-LASTING ENTERTAINMENT: Enjoy long-lasting fun. Finish your favorite series or book with a battery that can last up to 16 hours.¹ Need energy quick? Get a full charge in about two hours with Super Fast Charging.²
  • WRITE, DRAW, DO IT ALL: S Pen is mightier than your average writing tool. The responsive design and intuitive integration with intelligent features make drawing, jotting down notes and even doing math easier than ever
  • SPACE TO KEEP WHAT MATTERS MOST: More storage means deleting less apps, photos, videos and files. Galaxy Tab S10 Lite comes with up to 256GB³ of storage. And if you need even more, you can add up to 2TB with a microSD card.⁹
  • THE POWER OF ENHANCED PERFORMANCE: Galaxy Tab S10 Lite boasts an Exynos 1380 processor that lets you stream, scroll, note, search and even multitask with ease

Keep foreground and background semantics clear

An overlay is not merely cosmetic. Foreground text is appropriate for a visible annotation, while background text is useful for a watermark that should sit beneath existing page content. Check the result in a viewer because transparency, artwork, and unusual page content can affect what a reader sees.

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

Validate the saved PDF before distributing it

Check that the text is actually visible

Open the output file, navigate to every edited page, and inspect the exact region where text was inserted. This is essential for insert_textbox(), whose overflow can be invisible without a warning. Check short and long inputs if the text is generated dynamically.

Check page count, position, and dimensions

For a new-page workflow, verify that the page appears where intended and that its width and height match the surrounding document. For a merge workflow, compare the overlay page dimensions with the target page before relying on coordinate alignment.

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

Check the intended viewer

Render or open the saved PDF in the viewer used by your audience. The cited APIs document insertion and merge operations, but they do not promise that every complex PDF feature behaves identically after editing. A visual check catches clipping, missing text, unexpected layering, and page-order mistakes that a successful save call cannot detect.

Best Value
Sale
Tablet, 10.1 Inch Android 16 Tablets with Keyboard,24+64GB, 1TB Expansion | Android Tablet Bundle with Mouse, Stylus, Leather Case, Dual Camera, Face Unlock, Widevine L1, WiFi6 BT5.4
  • LATEST ANDROID 16 SYSTEM: Experience the cutting-edge Android 16 OS with enhanced privacy controls and ultra-smooth multitasking. Featuring 24GB RAM (3+21) and 64GB ROM storage, this tablet handles educational apps, business software, and streaming with zero lag | See less
  • 2-IN-1 VERSATILE LAPTOP MODE: Seamlessly transform your tablet into a high-productivity workstation. The comprehensive bundle includes a responsive Bluetooth keyboard and a silent wireless mouse, paired with a premium folding leather case that offers 360-degree protection and multiple viewing angles | See less
  • OPTIMIZED FOR STUDENTS AND PROFESSIONALS: Designed for online learning, digital note-taking, and remote collaboration. The high-sensitivity capacitive stylus allows for precise sketching and annotation, while dual HD cameras provide crystal-clear video quality for Zoom meetings and virtual classrooms during travel | See less
  • ULTRA-FAST WIFI6 AND PD CHARGING: Stay connected anywhere with high-speed dual-band WiFi for lag-free streaming and rapid file downloads. Equipped with a PD fast charging kit, this tablet significantly reduces recharge time, making it a suitable companion for long-haul business trips and outdoor use | See less
  • COMPLETE BUNDLE AND ONE-YEAR WARRANTY: What's in the box: 10 inch Android 16 Tablet, Bluetooth Keyboard, Wireless Mouse, Stylus Pen, Protective Leather Case, and PD Fast Charger. Includes One-year brand warranty and 24/7 technical support | See less

Troubleshoot common failures

The text is missing from a textbox

  • Increase the rectangle’s width or height.
  • Reduce the font size or shorten the text.
  • Split a long paragraph into multiple rectangles.
  • Save again and inspect the rendered output rather than relying only on a completed Python call.

The text is on the wrong page

Confirm the zero-based page index used by doc[0], doc[1], and so on. If you created a page, verify the insertion position returned by your workflow and then inspect the resulting page order.

The annotation is hidden behind existing content

Change the insertion’s overlay setting so the text is placed in the foreground. If the text is intended as a background watermark, keep the background setting and choose a color and position that remain visible around the page artwork.

A separately generated overlay does not line up

Compare the ReportLab canvas dimensions with the target page dimensions and revisit the coordinate origin and scale. A merge operation combines pages; it does not remove the need to design both pages on the same coordinate framework. Validate the merged PDF in the target viewer.

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

A practical decision checklist

  1. Need one or a few labels at known points? Open the PDF with PyMuPDF and call insert_text().
  2. Need wrapping inside a defined region? Use insert_textbox() and reserve enough width and height for the longest expected text.
  3. Need an appendix, cover sheet, or other standalone page? Use insert_page() with explicit page dimensions.
  4. Already generating independent PDF pages with a drawing library? Generate the page with ReportLab and combine it with pypdf, treating alignment as an explicit engineering task.
  5. Regardless of method, save to a new filename and verify the rendered result, page order, dimensions, layering, and visibility.

What this approach does—and does not—guarantee

PyMuPDF provides documented ways to insert text on new or existing PDF pages, including controls for position and presentation. That makes it a strong default for direct edits. The APIs do not constitute a cross-version compatibility matrix, and the documentation does not provide a universal guarantee that every complex input-PDF feature will be preserved. Record the installed library versions in your project, test against the PDFs your application actually receives, and keep the validation step in production workflows.

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.

document automationPDFPyMuPDFpypdfPythonReportLab

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.