Text search highlights

Product: PDFNet Node

Product Version: 9.4.0

Please give a brief summary of your issue:
Highlight multiple search results

Please describe your issue and provide steps to reproduce it:
I would like to loop through all search result highlights, but it seems only run for the first match.
Here is the code:

const doc = await PDFNet.PDFDoc.createFromFilePath("pdf-demo.pdf");
const txtSearch = await PDFNet.TextSearch.create();
await txtSearch.begin(
  doc,
  "1234",
  PDFNet.TextSearch.Mode.e_whole_word +
    PDFNet.TextSearch.Mode.e_page_stop +
    PDFNet.TextSearch.Mode.e_highlight
);
const result = await txtSearch.run();

if (result.code === PDFNet.TextSearch.ResultCode.e_found) {
  /** @type {PDFNet.Highlights} */
  const hlts = result.highlights;
  await hlts.begin(doc);

  while (await hlts.hasNext()) {
    const quadArr = await hlts.getCurrentQuads();
    console.log(quadArr);

    await hlts.next();
  }
}

The pdf file is very simple
pdf-demo.pdf (8.7 KB)

The log only shows 1 result and only run once, whilts I would expect 3 results

[
  {
    name: 'QuadPoint',
    p1x: 104.59599999999999,
    p1y: 556.9580000000001,
    p2x: 132.596,
    p2y: 556.9580000000001,
    p3x: 132.596,
    p3y: 574.9340000000001,
    p4x: 104.59599999999999,
    p4y: 574.9340000000001
  }
]

I believe this is the solution PDFTron Systems Inc. | Documentation

Updated code:

const doc = await PDFNet.PDFDoc.createFromFilePath("pdf-demo.pdf");

const txtSearch = await PDFNet.TextSearch.create();
await txtSearch.begin(
  doc,
  "1234",
  PDFNet.TextSearch.Mode.e_whole_word | PDFNet.TextSearch.Mode.e_highlight
);
let result = await txtSearch.run();

while (true) {
  if (result.code === PDFNet.TextSearch.ResultCode.e_found) {
    /** @type {PDFNet.Highlights} */
    const hlts = result.highlights;
    await hlts.begin(doc);

    while (await hlts.hasNext()) {
      const quadArr = await hlts.getCurrentQuads();
      console.log(quadArr);

      await hlts.next();
    }
  } else {
    break;
  }

  result = await txtSearch.run();
}

Hi Jackson,

The problem appears to be with your use of txtSearch.run()

As described in the documentation, run() only goes until an instance matching the search pattern is found. This means your code is only checking to see if any result is found, rather than all the results.

To search for the remainder, you need to re-run the txtSearch.run() method after every found result within your loop. Please take a look at the API for more information:
https://www.pdftron.com/api/PDFTronSDK/dotnet/pdftron.PDF.TextSearch.html#pdftron_PDF_TextSearch_Run_System_Int32__System_String__System_String__pdftron_PDF_Highlights_