HTML JPG PDF XML DOCX
  Product Family
PDF

Replace Text in PDF in Node.js SDK

Replace Text in a PDF Document using Cloud Node.js SDK.

Get Started

How to replace Text in PDF via Node.js SDK

To replace text in PDF, we’ll use Aspose.PDF Cloud Node.js SDK. This Cloud SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.

Package Manager Console Command


     
    npm install asposepdfcloud --save
     
     

Steps to replace Text using Node.js

Aspose.PDF Cloud developers can easily load & replace Text in PDF in just a few lines of code.

  1. Load your Application Secret and Key from the JSON file or set credentials in another way
  2. Create an object to connect to the Cloud API
  3. Upload your document file
  4. Perform the replacing the text using pdfApi.postDocumentTextReplace
  5. Download the result if needed it
 

Replace Text in PDF using Node.js


    async function () {
        const pdfApi = new PdfApi(credentials.id, credentials.key);
        try {
            const fileBuffer = await fs.readFile(LOCAL_FILE_NAME);
            await pdfApi.uploadFile(STORAGE_FILENAME, fileBuffer);
            const textReplaceList =
            {
                textReplaces:
                    [
                        { oldValue: "Black", newValue: "White" },
                        { oldValue: "2024", newValue: "2025" }
                    ]
            }
            const result = await pdfApi.postDocumentTextReplace(STORAGE_FILENAME, textReplaceList);
            console.log("Status:", result.body.status);
            const downloadRes = await pdfApi.downloadFile(STORAGE_FILENAME);
            await fs.writeFile(RESULT_FILENAME, downloadRes.body);
        }
        catch (error) {
            console.error(error.message);
        }
    }
 

Work with Text in PDF

Text replacement allows users to update outdated or incorrect information, such as addresses, dates, or pricing details, without recreating the entire document. It is also a quick way to fix typos, grammatical mistakes, or formatting issues, ensuring the document appears polished and professional. Replace Text in PDF documents with Aspose.PDF Cloud Node.js SDK.

With our Node.js library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & stamps (text or image) to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to replace the text in PDF files online and test the functionality.