Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

412
Views
How to extract page numbers from Word document via add-in built using the Word JavaScript API

in Word via an add-in built using the Word Javascript API, I'm trying to read the page number of each location a string of text appears in the document text. E.g. the word "HELP" appears on pages 2, 6, 10 and 45. How can I read the page number?

A stripped down version of the code I have so far is:

async function run() {
  await Word.run(async (context) => {
    let paragraphs = context.document.body.paragraphs;
    paragraphs.load("text"); // WHAT ELSE NEEDS TO BE LOADED TO ALLOW PAGE NO EXTRACTION?
    await context.sync();
    // loop through document to find text
    paragraphs.items.forEach((item) => {
      let paragraph = item.text.trim();
      if (paragraph.includes("EXAMPLE STRING")) {
        let pageNumber = what_goes_here?;
        console.log("Text found on page: " + pageNumber);
      }
    });
  });
}

This works fine for finding the text string, but I can't work out how to get the page number (pageNumber in the code above).

I've been through the Word API documentation but can't find anything. I can, for example, where the text is in a list extract the list level by loading the "listItemOrNullObject" object and reading the "listString", but I can't see any way to get the page number.

Any ideas? If this isn't available via the standard Word API (as I'm suspecting) has anyone got any workarounds?

I'd like to do this using JS and the Word API (great cross platform support etc.) and not have to use VBA, C# etc.

Thank you!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Currently there hasn't been such an JS API to return the page number of the selected text. You can post the API request here: https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/idb-p/Microsoft365DeveloperPlatform

Wenjun

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!