Page 1 of 1

Anchors and anchored text

Posted: 2020-12-29 23:20:56
by lellius
Trying to convert - with OCR - pdf files (especially pdf files of old prints) to text files, I get — besides text — a lot of anchors with anchored text inside.
There is no way to delete all these anchors with Nisus (or at least I didn’t find any up to now).
But in all cases I would better need a macro which could replace anchors and anchored text with the the text contained in the anchor. (eventually between square brackets).
Thanks in advance to everybody who can provide any hint.
lellius

Re: Anchors and anchored text

Posted: 2020-12-30 00:01:02
by phspaelti
Something like this?

Code: Select all

$doc = Document.active
foreach $float in $doc.allFloatingContents
  if $float.isTextBox
    $float.anchorText.insertAtIndex $float.anchorTextRange.location, '[' & $float.text & ']'
    $float.removeFromDocument
  end
end

Re: Anchors and anchored text

Posted: 2020-12-30 10:14:10
by lellius
Philip,
as usually you you are the first one.
The macro does work well, except it doesn't find and delete a void anchor.
Many thanks.
lelliius

Re: Anchors and anchored text

Posted: 2021-01-03 21:03:50
by phspaelti
Hello lellius, and happy new year!
lellius wrote: 2020-12-30 10:14:10 The macro does work well, except it doesn't find and delete a void anchor.
The reason is that I put in a condition which restricts processing to text boxes. I did it that way so it wouldn't delete any floating images.
I'm not sure what the "void" anchors would turn out to be. If you are happy deleting all anchors regardless of type (after processing the text boxes), you could change the macro as follows:

Code: Select all

$doc = Document.active
foreach $float in $doc.allFloatingContents
  if $float.isTextBox
    $float.anchorText.insertAtIndex $float.anchorTextRange.location, '[' & $float.text & ']'
  end
  $float.removeFromDocument
end
If you wanted to be more selective about what to delete and what not, one would have to know what kinds of floating contents are present in the document.

Re: Anchors and anchored text

Posted: 2021-01-10 11:08:40
by lellius
Philip.
Oddly enough I often can’t open nisus.com page and so I only now, after many days, could see how you fixed the macro. I have tried it already and up to now It does work just as I wanted. Many thanks again and happy new year (though late).
lellius