Skip to main content
Participant
October 23, 2019
Question

Search in PDF and add rectangle to text

  • October 23, 2019
  • 2 replies
  • 693 views

Hi all! Would really appreciate some help figuring out the proper code to help me at work. 
The idea is to be able to automatically search for phrases in a PDF document containing dollar signs (i.e "$24.7 million...."), or percents ("45% of sales") and then add in a red rectangle around that phrase. Can anyone give me a little guidance on how to do this? I am very new to the world of writing code so I would really appreciate the help with this. 
Thanks so much in advance! 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
October 25, 2019

It is possible, although identifying an entire phrase (as opposed to just the number with the symbol) is very complicated.

Either way it requires a custom-made script that will identify the matches and then add a Square comment around them.

I've developed very similar tools for my clients so if you're interested in hiring someone to create it for you feel free to contact me privately via [try6767 at gmail.com] and we could discuss it further.

ls_rbls
Community Expert
Community Expert
October 25, 2019

Hi,

 

This looks like an advanced search with with the ability to highlight the keywords punched in the search.

 

Have you tried any of the action tools freely available for download ?

 

Check the Adobe Tools and the Adobe Actions exchange page.

 

And also the Adobe for legal professionals.

 

There are various action tools that allow you to do something similar through extraction of pages and comments.

Cmk1815Author
Participant
October 25, 2019

Yes I was able to find some actions to search and highlight the text. However I was looking for a way to add a red box around the text, not highlight it. We usually do this individually and free drawn with the comment feature. I was hoping there was a way to automatically do it to the searches phrase. 

Thom Parker
Community Expert
Community Expert
October 26, 2019

 

You've already found your solution, i.e. the Action that searches and highlights text. I imagine you found this at the Acrobat User's Actions Exhange?  All you need to do is replace the hight annoation with a rectangle.

 

There are a couple of differnet ways to do this. First, though, here's how that Actio works. It uses the Redact search tool to place Redact Annotations on the searched words, then it replaces the Redact Annotations with Highlights.

 

1. Edit the JavaScript part of the action to replace the Redacts with "Squares".

2. Or, just run some code in the Console window to replace the Highlights with Squares.

 

Here's some example code that will convert all highlight annotations into squares. Note: the outline color of the square is the same as the highlight. 

 

this.getAnnots().forEach(function(a){if(a.type == "Highlight")a.type="Square";});

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often