Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Jun 11, 2021 Jun 11, 2021

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!

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
TOPICS
JavaScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2021 Jun 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 11, 2021 Jun 11, 2021
Ok.

What about copying the text as Proper Case?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2021 Jun 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2021 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2021 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2021 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2021 Jun 11, 2021
LATEST

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.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines