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

JavaScript search or find or get a number or number string on a page.

Community Beginner ,
Dec 08, 2022 Dec 08, 2022

I am looking to search a pdf using javascript to find a certain number, the index of a number or anything that would get a number string on a PDF. The closest thing I have found is "this.getPageNthWord" but that cannot get numbers. Any help would be appreciated. 

2.9K
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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 08, 2022 Dec 08, 2022

OK. Well, this code will print out all the words in the file with a digit in them (so even "1a" or "abc3xyz"):

 

for (var p=0; p<this.numPages; p++) {
	var numWords = this.getPageNumWords(p);
	for (var i=0; i<numWords; i++) {
		var word = this.getPageNthWord(p,i,true);
		if (/\d/.test(word)) console.println(word);
	}
}

View solution in original post

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 ,
Dec 08, 2022 Dec 08, 2022

in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

 

<moved from using the community>

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 ,
Dec 08, 2022 Dec 08, 2022

What happens when you use this function?

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 ,
Dec 08, 2022 Dec 08, 2022

 Numbers in a page, words on a page, symbols on a page. These are all characters of the same kind. getPageNthWord gets groups of characters, combined by guesswork into "words". What difficulty do you face reading strings of digits as numbers?

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 ,
Dec 08, 2022 Dec 08, 2022

I have a string of numbers on the page that was imported from using prepare forms "topComponent" feature. I would like to get the number string from off the page and use it in my JavaScript but when I use "this.getPageNthWord" it just skips over the number string completely. 

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 ,
Dec 08, 2022 Dec 08, 2022

What do you want to do with these numbers, once they are found?

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 ,
Dec 08, 2022 Dec 08, 2022

add them to a populated email but I know how to do that already 

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 ,
Dec 08, 2022 Dec 08, 2022

OK. Well, this code will print out all the words in the file with a digit in them (so even "1a" or "abc3xyz"):

 

for (var p=0; p<this.numPages; p++) {
	var numWords = this.getPageNumWords(p);
	for (var i=0; i<numWords; i++) {
		var word = this.getPageNthWord(p,i,true);
		if (/\d/.test(word)) console.println(word);
	}
}
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 ,
Dec 08, 2022 Dec 08, 2022
LATEST

It worked great! Thanks so much! 

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