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

Split PDF using an Action with Java Scipt.

New Here ,
Feb 01, 2017 Feb 01, 2017

Our company needs to split mulitple pdf files.  The files must = 25 pages or less after spliting.  For example 102 page file would output 5 files.  4=25pages, and 1=2 remaining pages. I have a script but it only outputs 2 pages.

/*Extract pages 25 at a time with leading zerors for proper sort */

function padLeft (s,len,c){

c=c || '0';

while (s.length< len) s= c+s;

return s;

}

// regular expression used to acquire the base name of file

var re = /\.pdf$/i;

//file name is the base name of the file acrobat is working on

var filename = this.documentFileName.replace (re,"");

try {for (var i = 0; (i*2) < this.numPages; i++)

this.extractPages({

nStart: i * 2,

nEnd: (i * 2) + 1,

cPath: filename + "-" + padLeft ((i + 1) + "",3) +".pdf"

});

} catch (e) { console.println("Aborted: " + e)}

TOPICS
Acrobat SDK and JavaScript
787
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 , Feb 01, 2017 Feb 01, 2017

This code should work better:

for (var i=0; i<this.numPages; i+=25) {

    var startPage = i;

    var endPage = i+24;

    if (endPage>=this.numPages)

        endPage = this.numPages-1;

    this.extractPages({

        nStart: startPage,

        nEnd: endPage,

        cPath: "..."

    });

}

Translate
Community Expert ,
Feb 01, 2017 Feb 01, 2017

This code should work better:

for (var i=0; i<this.numPages; i+=25) {

    var startPage = i;

    var endPage = i+24;

    if (endPage>=this.numPages)

        endPage = this.numPages-1;

    this.extractPages({

        nStart: startPage,

        nEnd: endPage,

        cPath: "..."

    });

}

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 ,
Feb 01, 2017 Feb 01, 2017
LATEST

Thank you- worked perfectly.

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 ,
Feb 01, 2017 Feb 01, 2017

That's what it is written to do. Adjust the loop counters and the nStart and nEnd.

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