Skip to main content
New Participant
December 8, 2022
Answered

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

  • December 8, 2022
  • 4 replies
  • 3084 views

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. 

    Correct answer try67

    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);
    	}
    }
    

    4 replies

    try67
    Braniac
    December 8, 2022

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

    New Participant
    December 8, 2022

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

    try67
    try67Correct answer
    Braniac
    December 8, 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);
    	}
    }
    
    Braniac
    December 8, 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?

    New Participant
    December 8, 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. 

    Bernd Alheit
    Braniac
    December 8, 2022

    What happens when you use this function?

    kglad
    Braniac
    December 8, 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>