Skip to main content
dj0691
Participating Frequently
November 26, 2019
Question

Need to find all words that have a hyphen and are the last word in a sentence, ie , have a '.'

  • November 26, 2019
  • 3 replies
  • 1046 views

Im looking for a way in Adobe Acrobat to highlight all words, of varying length, that contain a hypen and are followed by a period, ie, the last word in a sentence.  Examples may be "con-tinued." or "wood-grain.".  Ideally this would be part of an Adobe Action so users can easily access.  Is this a relatively simple JavaScript?

This topic has been closed for replies.

3 replies

Thom Parker
Community Expert
Community Expert
December 2, 2019

There is actually an easy way to do this, which is to use the Redaction search. 

Since you have a custom search pattern, you'll need to add your pattern to the ones provided by Adobe. 

Here's an article on the process.

https://blogs.adobe.com/acrolaw/2011/05/creating_and_using_custom_redact/

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
November 26, 2019

> Is this a relatively simple JavaScript?

Not really. For starters, you will need to learn how to read the contents of a PDF file using JS, which involves looping over all the words in it. Let's say you've done that and you were able to write a Regular Expression to identify those words that end with a hyphen (as a hyphen breaks a word into two parts. Also, keep in mind there are multiple types of hyphens and dashes, and that not all the ones you see on the page are actually there, depending on how the file was set up). Now you need to examine the word after this word and see if that one ends with a period (similar to the previous task). If so, you need to learn how to retrieve the quads of those two words, combine them and then add an annotation over both of them.

All of this requires quite a bit of knowledge of the Acrobat JavaScript model and its various objects, methods and properties. If you're doing this for a job I would recommend hiring someone to do it for you. If you're learning how to use Acrobat JS then it's a neat project, but might be a bit much for beginners.

ls_rbls
Community Expert
Community Expert
November 26, 2019

Hi, 

 

See Thom Parker quick guide here on using javascript for text  matching regular expressions:

https://acrobatusers.com/tutorials/text-matching-regular-expressions