Skip to main content
Known Participant
June 30, 2016
Answered

Translate a PDTextSelect variable to a PDEElement

  • June 30, 2016
  • 3 replies
  • 734 views

I'm working with a PDTextSelect variable in order to get user selected text. Is there any way to then turn this PDTextSelect varible into a PDEElement? I have tried a couple of thing so far including reinterpret_cast<PDEElement> but nothing has worked.

This topic has been closed for replies.
Correct answer Test Screen Name

There is no direct conversion. They are entirely different kinds of representation. The order of text and characters may not even be the same. Once you have the coordinates of a PDTextSelect you can iterate the PDEText elements to find the elements (not necessarily consecutive) which overlap in the coordinates. The selection is likely to be only a portion of a PDETextRun. This is complicated stuff (albeit important and an obvious need). Text editing is a very complex task and generally works entirely in the PDF edit layer, implementing its own selection logic.

3 replies

LWShayAuthor
Known Participant
July 1, 2016

Okay, that helps a lot. I'll give it a try.

LWShayAuthor
Known Participant
June 30, 2016

I'm trying to find the selected text in the content tree

lrosenth
Adobe Employee
Adobe Employee
June 30, 2016

Then you basically need to do what TSN described.

Walk the contents (PDEElements) and compare the bounding boxes to find those inside the selection rectangle.

Test Screen NameCorrect answer
Legend
June 30, 2016

There is no direct conversion. They are entirely different kinds of representation. The order of text and characters may not even be the same. Once you have the coordinates of a PDTextSelect you can iterate the PDEText elements to find the elements (not necessarily consecutive) which overlap in the coordinates. The selection is likely to be only a portion of a PDETextRun. This is complicated stuff (albeit important and an obvious need). Text editing is a very complex task and generally works entirely in the PDF edit layer, implementing its own selection logic.

lrosenth
Adobe Employee
Adobe Employee
June 30, 2016

As TSN says, this is not a trivial piece. What do you need the PDEElement for? Perhaps there are other structures that are easier to work with from the PDTextSelect that you could use instead.