Anchors and anchored text

Get help using and writing Nisus Writer Pro macros.
Post Reply
lellius
Posts: 51
Joined: 2002-08-15 22:06:44

Anchors and anchored text

Post 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

User avatar
phspaelti
Posts: 1166
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Anchors and anchored text

Post 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
philip

lellius
Posts: 51
Joined: 2002-08-15 22:06:44

Re: Anchors and anchored text

Post 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

User avatar
phspaelti
Posts: 1166
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Anchors and anchored text

Post 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.
philip

lellius
Posts: 51
Joined: 2002-08-15 22:06:44

Re: Anchors and anchored text

Post 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

Post Reply