Skip to main content
Participant
June 11, 2021
Question

Script to Copy Text in Proper Case (Each Word Capitalized)

  • June 11, 2021
  • 4 replies
  • 1855 views

I want to create a script that would copy any selected text in a PDF and convert the copied to proper case onto the clipboard.

 

THIS IS UPPERCASE

1. Select the above phrase

2. Click the custom script button

3. The system copies a Proper Case version of the selected text to the clipboard.

 

Ideas?

 

Thanks!

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
This topic has been closed for replies.

4 replies

J E L
Community Expert
Community Expert
June 11, 2021

You first need to define if you want sentence case or title case. If title case, that can change based on a set of style parameters, such as Chicago Manual of Style or AP Style. 

 

THIS IS ALL CAPS.

This is sentence case.

This Is Tile Case in Chicago.

Title Case Won't Be the Same When Using AP Style in Terms of Which Letters Are Capitalized.

 

 

try67
Community Expert
Community Expert
June 11, 2021

You can use this function to convert a string to this "proper" case (I know it as Title Case):

 

function toTitleCase(s) {
	var words = s.split(" ");
	for (var i in words)
		words[i] = words[i].charAt(0).toUpperCase() + words[i].substr(1).toLowerCase();
	return words.join(" ");
}

Note that the above can yield strange results. For example, if you run it on "I'm going to visit the USA.", it will return "I'm Going To Visit The Usa."...

 

As mentioned, though, copying the text to the clipboard is tricky.

Legend
June 11, 2021

Sure, if you can define "proper" case (which would not normally be "Proper Case" for English) then JavaScript can do it. HOWEVER, you can't put it back on the page to copy. Better to process it with an external app once it's on the clipboard.

Legend
June 11, 2021

Sorry, I see you use "Proper Case" as a technical term from Visual Basic. Not sure what makes it proper. But at least it's much easier to do than camelCase.

Thom Parker
Community Expert
Community Expert
June 11, 2021

The Acrobat JavaScript model does not provide direct access to the selected text or the clipboard.  However, an indirect/partial solution would be a script that runs the Copy menu item.

 

app.execMenuItem("Copy", this);

 

It's a partial solution because the context of the copy is not guarenteed to be the selected text.

I also think this might require a privileged context.

https://www.pdfscripting.com/public/Trust-and-Privilege-in-Acrobat-Scripts.cfm

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
June 11, 2021
Ok.

What about copying the text as Proper Case?
Thom Parker
Community Expert
Community Expert
June 11, 2021

It is what it is. Did I mention that the Acrobat JavaScript model does not provide direct access to the selected text or the clipboard. 

 

That said, the case alway comes through for me.

What happens when you copy and paste text manually?  Does the case copy as well?  If not then this is an issue with your operating system, not Acrobat. Acrobat is just pushing text data out to the system. The system decides what to paste. 

 

 

 

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