IRONSOFTWAREHOME
Text Find and Replace
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    // Render new PDF document
    const pdf = await PdfDocument.fromHtml("<h1>.NET6</h1>");

    // Parameters
    const pageIndex = 0; // Page index (zero-based)
    const oldText = ".NET6"; // Old text to remove
    const newText = ".NET7"; // New text to add

    // Replace text on the specified page
    await pdf.replaceText(oldText, newText, pageIndex);

    // Save the modified PDF document
    await pdf.saveAs("newSample.pdf");
})();
npm i @ironsoftware/ironpdf
Text Find and Replace

Text Find and Replace

This code example demonstrates how to replace specific text in any PDF document. This feature can be applied to both newly rendered and existing PDFs.

To replace text in a PDF document, you can utilize the replaceText method. It requires three arguments: the old text to find, the new text to replace it with, and the page index where this replacement should take place. In this example, it substitutes ".NET6" with ".NET7" on the specified page.

Once the text replacement is completed, you can save the modified PDF document using the SaveAs method. For more information on how to manipulate and manage PDF files, visit the IronPDF Features Page.

Additionally, you can explore other powerful tools offered by Iron Software, such as IronOCR for OCR capabilities, IronBarcode for barcode generation and reading, or IronSoftware.com for a full list of products.

Explore the Replace Text in PDF Code Example on GitHub
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Node.js Module Download for PDF
Install with npm

Version: 2026.8

  1. Download and install Node.js 12+.
  2. Execute the above command in the terminal.

Licenses from $999