Highlighting with JS

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
dustinbagley
User
Posts: 22
Joined: Wed Aug 02, 2023 4:19 pm

Highlighting with JS

Post by dustinbagley »

I'm trying to highlight a word with javascript. For the life of me, I can't get anything but the bowtie. The output seems to be different between highlight and a square but I'm not sure how.

The script I've trying to get to work looks as follows:

for (var p = 0; p < this.numPages; p++)
{
var numWords = this.getPageNumWords(p);
for (var i=0; i<numWords; i++)
{
var ckWord = this.getPageNthWord(p, i, true);
if ( ckWord == "NOTES")
{
var q = this.getPageNthWordQuads(p, i);

var annot = this.addAnnot(
{
type: "Highlight",
page: p,
rect: q,
author: "A. C. Robat",
strokeColor: color.yellow,
}
)
}
}
};

I've seen that sometimes the quads are split and inverted etc which seems to work with a square, but the highlight always ends in a bowtie for me. Any help would be appreciated. thanks
2023-10-09 16_08_31-101 - Kickplate Walkway 1 X Space - Master_ - PDF-XChange Editor.png
You do not have the required permissions to view the files attached to this post.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Highlighting with JS

Post by Tracker Supp-Stefan »

Hello dustinbagley,

You are getting quads - which are 8 values, and are then trying to apply them to the rectangle for your annotation which expects only four.

Please try this code (only the rect: is replaced with quads: for the annotation) - and it should work for you - it did for me:

Code: Select all

for (var p = 0; p < this.numPages; p++)
{
  var numWords = this.getPageNumWords(p);
  for (var i=0; i<numWords; i++)
  {
    var ckWord = this.getPageNthWord(p, i, true);
    if ( ckWord == "YourWordHere")
    {
      var q = this.getPageNthWordQuads(p, i);

      var annot = this.addAnnot(
      {
        type: "Highlight",
        page: p,
        quads: q,
        author: "A. C. Robat",
        strokeColor: color.yellow,
      }
      )
    }
  }
};
Kind regards,
Stefan
dustinbagley
User
Posts: 22
Joined: Wed Aug 02, 2023 4:19 pm

Re: Highlighting with JS

Post by dustinbagley »

Thank you
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8624
Joined: Wed Jan 03, 2018 6:52 pm

Highlighting with JS

Post by TrackerSupp-Daniel »

:)
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com