GoTo/op.search char with position?

PDF-XChange Editor SDK for Developers

Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

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.
khho
User
Posts: 54
Joined: Fri Mar 11, 2022 11:02 am

GoTo/op.search char with position?

Post by khho »

Dear team,
I got the start and the end position of a string in PDF file. The first character in the file has position 0, the last the last :D .

How can I jump/goto/search to this character/string in the document?

I know how to search a string with

Code: Select all

Inst.Str2ID("op.search", false);
but I don't know how it works with position.


Cheers
khho
zarkogajic
User
Posts: 1464
Joined: Thu Sep 05, 2019 12:35 pm

Re: GoTo/op.search char with position?

Post by zarkogajic »

Hi,
How can I jump/goto/search to this character/string in the document
Can you explain a bit more, maybe with a screen shot of the desired result ...

-žarko
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19846
Joined: Mon Jan 12, 2009 8:07 am

Re: GoTo/op.search char with position?

Post by Stefan - PDF-XChange »

Hello zarkogajic,

Thanks for posting in this topic.
I did look at the JS API reference - and can not see a way to use the Search with ID positions, so this is likely not going to be possible, but as you said - some example will certainly help!

Kind regards,
Stefan
NicoDN
User
Posts: 2
Joined: Tue May 13, 2025 10:12 am

Re: GoTo/op.search char with position?

Post by NicoDN »

Is it still possible to jump to a specific position in the document via the API? For example, to the 200th character in the document?

Regards
Nico
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19846
Joined: Mon Jan 12, 2009 8:07 am

Re: GoTo/op.search char with position?

Post by Stefan - PDF-XChange »

Hello NicoDN,

Welcome to our forums.

PDF files are not "flowing text" ones - so there could be one object per character, and not a single "word" of text that is one object. As such determining which is the 200th character in a file might be tricky. As such you can navigate to a precise coordinate position, but as far as I am aware you can't really go to the position of a specific character symbol (without grabbing the coordinates of that first which I am not sure is possible using JS alone).

Kind regards,
Stefan
khho
User
Posts: 54
Joined: Fri Mar 11, 2022 11:02 am

Re: GoTo/op.search char with position?

Post by khho »

Stefan - PDF-XChange wrote: Tue May 13, 2025 11:41 am Hello zarkogajic,

Thanks for posting in this topic.
I did look at the JS API reference - and can not see a way to use the Search with ID positions, so this is likely not going to be possible, but as you said - some example will certainly help!

Kind regards,
Stefan
Hi again,
as an example: in the the attached screenshot I found '456' by text search. I want to find, goto and highlight it by 'searching' the text position.

khho
You do not have the required permissions to view the files attached to this post.
zarkogajic
User
Posts: 1464
Joined: Thu Sep 05, 2019 12:35 pm

Re: GoTo/op.search char with position?

Post by zarkogajic »

Hi,

You want to programmatically do what the "Find" dialog does: search for some text and have it highlighted?

-žarko
NicoDN
User
Posts: 2
Joined: Tue May 13, 2025 10:12 am

Re: GoTo/op.search char with position?

Post by NicoDN »

For example: We are looking for the text “This is a test”. But it should only be marked once. We know that the text to be marked is to be searched for after character position 100.
So the challenge is to mark a text that can occur several times in the document but should only be marked once at a specific character position
1.png
You do not have the required permissions to view the files attached to this post.
khho
User
Posts: 54
Joined: Fri Mar 11, 2022 11:02 am

Re: GoTo/op.search char with position?

Post by khho »

zarkogajic wrote: Fri May 16, 2025 11:00 am Hi,

You want to programmatically do what the "Find" dialog does: search for some text and have it highlighted?

-žarko
Dear -žarko,
no, I know how to search programmatically (see my first posting).
I want to go to text at position 4, highlight 4 to 6 programmatically.

Cheers,
khho
zarkogajic
User
Posts: 1464
Joined: Thu Sep 05, 2019 12:35 pm

Re: GoTo/op.search char with position?

Post by zarkogajic »

Hi NicoDN,

[Are you working together with "khho" user?]

Please note what Stefan replied: viewtopic.php?p=193235#p193235

PDF documents are not plain text files or Word documents - where it makes sense to talk about "word / character position". In a PDF document text can be over other text and in a different layer .. etc...

However, try the following (pseudo):

IPXC_Page _page = IPXC_Document.GetPage
IPXC_PageText _pageText = _page.GetText
_pageText.Get_LinesCount

for each line
_pageText.Get_LineInfo
_pageText.GetChars

In theory (I have not tried) you then look for your searched-for-string inside sChars and also increment nCharsCount for each processed line. Note that your searched-for-string can span between multiple lines.

Once you have found your searched-for-string, you need to get the PXC_Rect of the searched-for-string using _pageText.CharRect.

And finally, IPXV_Document.AddNewHighlighter.Add(page, ...)

HTH.

p.s.
Not an official support person :)

-žarko
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10998
Joined: Wed Jan 03, 2018 6:52 pm

Re: GoTo/op.search char with position?

Post by Daniel - PDF-XChange »

Hello,

Thank you Zarko!

In addition to what you have mentioned here, and I believe Stefan touched on it in the other thread, but I wanted to iterate on it a bit in this topic. Since PDF uses a coordinate based system, there will be times where the text in "content order" is not in alignment with the visual order.

One very common example of this is headers/footers, which often are all collected together, either all as the "first" or "last" few text items on a page. This would negatively impact your ability to accurately account for the character position in the context of each page.

You could also run into cases where some text is contained inside of nested Xform items, and you may encounter many cases where documents have dozens of invisible characters for no discernable reason on one line, and then on the next, it is properly formatted, and there is no space character at all between the text in two separate cells from a table.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

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