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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use PyMuPDF when you need to write on an existing PDF page. Its Page.insert_text() method places line-oriented text at a point, while Page.insert_textbox() wraps text inside a rectangle. If the text belongs on its own page, use Document.insert_page() instead. A ReportLab-generated page combined with pypdf is another option when you deliberately want a separate composition step.

The important choice is not the wording of the label or note; it is where the text should live and how tightly its size and position must be controlled. The examples below show each documented approach, the settings that affect appearance, and the checks that prevent a saved PDF from silently losing text.

Choose the PDF text operation before writing code

Decide whether you are modifying an existing page, filling a bounded area, or creating a new page. These are different operations even though all of them result in visible text.

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.
Reader need Documented approach What you control
Place a short label, note, page number, or watermark at a known point on an existing page PyMuPDF Page.insert_text() Start point, font, size, color, rotation, line count, and foreground/background overlay behavior
Put a paragraph or field inside a bounded region PyMuPDF Page.insert_textbox() Rectangle dimensions, automatic wrapping, alignment, font, size, color, rotation, and overlay behavior
Add a page that contains text instead of changing an existing page PyMuPDF Document.insert_page() Insertion position, page width and height, text, font size, font name, and color
Generate a text page separately and compose it with another PDF ReportLab drawing followed by pypdf page operations Canvas text drawing, page composition order, insertion position, dimensions, and the alignment between the two PDFs

Use the first method for a precise, point-based annotation. Use the second when the content must stay inside a box. Use the third when a cover sheet, appendix, or text-only page is the real requirement. The ReportLab-plus-pypdf route is a workflow architecture rather than a single overlay call, so it requires more validation of page size and coordinates.

#1 Best Overall
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.

Prepare the document and make a safe working copy

Open a copy of the source file and save to a different output path while developing. This preserves the original if a coordinate, font, or page-selection mistake produces an unusable result.

  1. Record the installed library version. PyMuPDF and pypdf APIs can change across releases. Confirm the version in the environment where the script will run and check the matching API documentation.
  2. Identify the target pages. A zero-based page index such as doc[0] addresses the first page. For a batch operation, decide whether every page receives text or only pages selected by number or content.
  3. Measure the page and the available blank space. Text coordinates and rectangles are expressed in PDF points. Leave enough room for ascenders, descenders, line spacing, and any existing artwork underneath.
  4. Choose a readable style. Set a font, size, and color explicitly when the default is not suitable. Check contrast against the page background before distributing the file.
  5. Plan an output check. The fact that a save call succeeds does not prove that every character fits or that every feature of a complex source PDF was preserved.

Keep the input and output filenames separate in examples and production jobs. That makes it possible to compare the original and edited pages visually and to rerun the script without compounding edits.

Overlay line-oriented text with Page.insert_text()

insert_text() is the direct choice for a label or a small number of lines whose starting point is known. It writes on an existing page and exposes controls for the start point, font, size, color, rotation, and whether the new content is drawn in front of or behind existing page content.

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

Minimal point-based example

import fitz  # PyMuPDF

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

page.insert_text(
    (72, 72),
    'Approved copy',
    fontsize=12,
    fontname='helv',
    color=(0, 0, 0),
    rotate=0,
    overlay=True,
)

doc.save('output-with-text.pdf')
doc.close()

The point tuple is the insertion start. Increase its horizontal or vertical values to move the text within the page. The font name and size determine how much space each line consumes; color changes the drawing color; and rotate changes the text orientation. Set overlay=True when the annotation should sit in the foreground. Choose the background setting when the intended result is for existing page artwork to remain over the inserted text.

Handling several lines

For line-oriented content, include line breaks in the string or build a string from a list of lines. Plan the number of lines so they remain inside the page height. The documented recipe notes that surplus lines are not written when the requested content runs beyond the available page height, so a successful save does not guarantee that every line appears.

lines = 'Invoice reviewnChecked by: A. PatelnDate: 2026-10-18'
page.insert_text(
    (72, 120),
    lines,
    fontsize=10,
    fontname='helv',
    color=(0, 0, 0),
    rotate=0,
    overlay=True,
)

Use a separate insertion call when two blocks need different sizes, colors, rotations, or overlay order. Keeping a heading and its body in separate calls also makes it easier to adjust one block without disturbing the other.

When point placement is the right fit

  • A short “Draft” or “Approved” stamp at a fixed location.
  • A page number positioned in a header or footer.
  • A watermark whose rotation and color are known in advance.
  • A signature note or review instruction that does not need automatic wrapping.

If the text length is variable or the available area is narrow, switch to a rectangle rather than guessing a start point and hoping the line ends before the margin.

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

Wrap text inside a rectangle with Page.insert_textbox()

insert_textbox() is designed for bounded content. You supply a rectangle, and PyMuPDF wraps the text to its width. The method also exposes presentation controls such as font, size, color, alignment, rotation, and overlay behavior.

Rectangle-based example

import fitz  # PyMuPDF

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

box = fitz.Rect(72, 140, 300, 220)
page.insert_textbox(
    box,
    'This note is constrained to a rectangle. It wraps to the available width.',
    fontsize=11,
    fontname='helv',
    color=(0, 0, 0),
    align=0,
    rotate=0,
    overlay=True,
)

doc.save('output-boxed-text.pdf')
doc.close()

The rectangle’s four coordinates define the usable area. Make it wider for fewer lines, taller for more lines, or both when the text is likely to vary. Alignment controls how lines sit within the box; use the alignment value documented for the version installed in your environment.

Rank #2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
  • Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.
  • Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
  • Read & Annotate. Enjoy intuitive reading modes and powerful tools to comment, highlight, and mark up PDFs.
  • Create & Manage PDFs. Create new PDFs, combine multiple files, scan documents, and compress for easy sharing.
  • Fill & Sign Forms. Complete forms and digitally sign documents with secure e-signature tools.

The overflow failure that is easy to miss

Text that does not fit inside the rectangle can be invisible without a warning. This is the most important difference between a box insertion and a simple save operation: a PDF can be produced even though the bottom of a paragraph never appears.

  1. Start with a rectangle larger than the minimum you think you need.
  2. Use a smaller font only after confirming that readability remains acceptable.
  3. Keep long content in a separate text block when one box would become too tall.
  4. Open the saved PDF and inspect the entire rectangle, including its last line.
  5. Render the page or inspect it in the viewer used by your recipients, because clipping can be apparent in one viewer and easy to miss in another.

Do not treat the method’s completion or the existence of an output file as proof of fit. The rendered page is the authority for a production workflow.

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.

Choosing between the two existing-page methods

Use insert_text() when you know the start point and want line-oriented placement. Use insert_textbox() when the content must wrap, align, or stay within a visible region. Both methods can be styled and rotated, and both can be placed in the foreground or background; the rectangle method adds the responsibility of sizing and checking the box.

Add a new text page with Document.insert_page()

Sometimes the requested result is not an annotation on an existing page at all. A cover page, explanatory note, or appendix can be added as a new page with Document.insert_page(). This avoids competing with existing page artwork and gives the new content its own dimensions.

import fitz  # PyMuPDF

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

page_number = doc.insert_page(
    -1,
    text='Processing notesnnThis page was added by the PDF workflow.',
    fontsize=12,
    width=595,
    height=842,
    fontname='helv',
    color=(0, 0, 0),
)

doc.save('output-with-new-page.pdf')
doc.close()

The insertion position determines where the page is added. The example uses a final-page position and explicit width and height; choose dimensions that match the document’s intended paper size. The documented default text start location is 50 points from the left and 72 points from the top when using this text-page facility. If that margin is unsuitable, create the page with dimensions that give the text enough room or use an existing-page method when precise placement is required.

Because the new page is independent, it is a good place for long text that would otherwise overflow a small rectangle. It is not a substitute for a footer or label that must appear on every existing page.

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

Generate a separate text page with ReportLab, then merge with pypdf

A two-library workflow is useful when your application already produces pages with ReportLab’s pdfgen canvas or when you want a dedicated composition phase. ReportLab draws strings at canvas coordinates. pypdf then appends pages or merges page content, and its merge operation accepts an insertion position.

The practical sequence is:

  1. Create a temporary PDF page with ReportLab and draw the required strings at canvas coordinates.
  2. Open the original PDF and the generated page with pypdf.
  3. Append the generated page as a new page, or merge it into a selected page using the merge operation and its insertion position.
  4. Ensure that the temporary page’s width and height match the target page before relying on coordinates.
  5. Write the composed document to a new file and inspect the result.

This architecture gives you separation between text generation and page composition, but it is not a universal overlay recipe. Coordinate alignment, page dimensions, scaling, rotation, and preservation of complex input features all need to be verified for the documents you process. The available documentation supports the drawing and merge building blocks; it does not establish one complete set of scale-handling rules for every PDF.

Validate the saved PDF instead of trusting the save call

Validation should be part of the script’s workflow, not an optional visual check after deployment. The cited APIs document insertion behavior, but they do not promise that every feature of every input PDF will be preserved identically.

Rank #3
Scrivar PDF Pro - Organize, Edit, Compress, Convert, Merge, eSign, OCR & 30+ tools | Lifetime License
  • EVERY PDF TOOL UNLOCKED - 30+ tools in one app: edit text and images, convert, merge, split, compress, sign, OCR, redact, watermark, batch process, and more. No feature gates, no upsells, nothing held back.
  • PAY ONCE, OWN FOREVER — A one-time purchase, not a subscription. Other apps runs $240/year — Scrivar is yours for life, with free updates included.
  • UNLIMITED eSIGN, BUILT IN — Send contracts and forms for signature and track every step. Recipients sign in their browser with no account or app needed. Replace DocuSign and save hundreds a year.
  • PC, MAC, AND WEB — Install on any Win 10/11 PC or macOS 11+ Mac (Intel or Apple Silicon), or work in your browser at scrivar.com. Same tools, same account, everywhere you work.
  • OCR + FULL OFFICE CONVERSION — Turn scanned documents into searchable, selectable text, and convert PDFs to and from Word, Excel, and PowerPoint with formatting kept intact.
  • Open the output in the intended viewer. Confirm that inserted text appears on the expected page and that characters, rotation, and color look correct.
  • Render pages when possible. A rasterized preview makes clipped textbox content, low contrast, and wrong overlay order obvious.
  • Check the page count. A new-page operation should change the count in the way you intended; an existing-page overlay should not add a page.
  • Inspect the edges of every text box. Look specifically at the final wrapped line and at descenders near the lower boundary.
  • Compare a complex source. PDFs containing forms, annotations, transparency, unusual fonts, or layered artwork deserve a before-and-after check in the viewer your users rely on.
  • Keep the original. If a feature changes unexpectedly, return to the source and try the alternative method rather than repeatedly editing the already modified file.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot by symptom

No text appears

Confirm that the script selected the intended page index and saved the output file you opened. Check that the start point or rectangle lies inside the page. For a textbox, enlarge the rectangle and shorten the text to determine whether the cause is overflow. Also verify that the text color contrasts with the page and that a foreground insertion was not intentionally placed behind opaque artwork.

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

Only part of a paragraph appears

This is usually a rectangle-sizing problem. Increase the rectangle’s height or width, reduce the font size, or split the content into multiple boxes. Reopen the output and inspect the last line; do not assume that a completed method call means all input characters were written.

The text is behind the page artwork

Change the insertion’s overlay setting so the text is drawn in the foreground. If the design intentionally calls for a watermark behind content, retain the background setting but choose a lighter color and verify that it remains visible.

The text is on the wrong page

Review the page index used to obtain the page object and print or otherwise inspect the document’s page sequence before inserting. For a new page, review the insertion position passed to insert_page(); a final-page position and a beginning-page position produce different reading orders.

The separate-page merge is misaligned

Compare the ReportLab canvas dimensions with the target PDF page dimensions. A mismatch can shift every coordinate even when each library’s drawing call is correct. Check rotation and scaling before changing individual text coordinates, then render the merged page to confirm the fix.

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

Practical patterns for labels, watermarks, and notes

Apply a label to selected pages

Open the document once, select each target page, and call insert_text() with the same style and position. Keep the page-selection rule separate from the insertion code so a later change does not accidentally label every page.

Keep a variable note inside a fixed area

Use insert_textbox() for the note and reserve a rectangle with generous height. If the note can grow beyond that space, measure and shorten it before insertion or move it to a new page. The final rendered output, not the input string length alone, determines whether the design works.

Create an explanatory appendix

Use insert_page() when the note deserves a full page and should not obscure original content. Set the page dimensions deliberately and review the resulting reading order.

Final decision checklist

  1. Is the text an overlay on an existing page, content inside a bounded region, or an entirely new page?
  2. For an overlay, is a fixed start point sufficient, or does the content need wrapping and alignment?
  3. Have font, size, color, rotation, and foreground/background behavior been set intentionally?
  4. Will the rectangle definitely hold every line at the chosen size?
  5. Does a separate ReportLab page match the target page dimensions before pypdf merges it?
  6. Did you save to a new file and inspect the result in the intended viewer?
  7. Did you test the method against the actual PDF features your workflow must preserve?

For most edits to an existing page, start with PyMuPDF and choose between point placement and a rectangle. Add a page when the content should stand alone. Use the ReportLab-and-pypdf composition route when a separate generation step is valuable, but treat coordinate alignment and output validation as part of the implementation rather than assumptions.

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

Quick Recap

Bestseller No. 1
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$99.99
Bestseller No. 2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.; Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
$99.99

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.