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

Find a sequence of numbers in a pdf

New Here ,
Jun 18, 2018 Jun 18, 2018

Hello.

I want to be able to find a sequence of ten numbers in a pdf. I was thinking of reading through each character of the pdf and using an if statement with the isNaN function, however, I'm not sure if that's even possible because I don't know how to read each character in a pdf. If there is another method on how to do this, then that would be fine, too.

Any help or guidance would be appreciated.

Thank you.

TOPICS
Acrobat SDK and JavaScript
1.0K
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

correct answers 1 Correct answer

Community Expert , Jun 18, 2018 Jun 18, 2018

Use a loop to iterate over all the words in all the pages in the file (using the getPageNthWord and the getPageNumWords methods of the Document object), and then a simple Regular Expression to check if it's a 10-digit number. Something like this:

loop1:

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{10}$/.test(word)) {

            console.println("Found it: " + word

...
Translate
Engaged ,
Jun 18, 2018 Jun 18, 2018

You wish to find ANY sequence of 10 numbers or a particular sequence?

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 18, 2018 Jun 18, 2018

Also, are these numbers joined to a single "word", or are they separated by

spaces/commas/hyphens/etc.?

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
New Here ,
Jun 18, 2018 Jun 18, 2018

It's formatted like...

1234567891

And I want to get the sequence as it is in the pdf.

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 18, 2018 Jun 18, 2018
LATEST

Use a loop to iterate over all the words in all the pages in the file (using the getPageNthWord and the getPageNumWords methods of the Document object), and then a simple Regular Expression to check if it's a 10-digit number. Something like this:

loop1:

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{10}$/.test(word)) {

            console.println("Found it: " + word);

            break loop1;

        }

    }

}

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