Javascript to remove blank pages from PDFs
top of page

Javascript to remove blank pages from PDFs


Evermap has posted the below Javascript here , which is designed to delete blank pages, (blank in the sense that they don't contain any searchable text), from sets of PDFs. I successfully tested the script tonight.

In order to run the script in Adobe Acrobat go to Tools . . . Action Wizard and click 'Create New Action . . . '. Under 'More Tools', in the 'Choose tools to add' section, click on 'Execute Javascript', then uncheck 'Prompt User' and click on 'Specify Settings' on the right. Put the script in the JavaScript Editor . . .

Click OK and save and rename the new action. Add the files you want to process and then click start.

A new file will be created for each source file, with the blank pages removed and '_Original' added to the end of the file name.

// Acrobat JavaScript Code - www.evermap.com // DELETE PDF PAGES WITHOUT TEXT // IMPORTANT: This script assumes that page is blank if it does not contain any "pdf words" // OUTPUT: An output PDF file is created by appending _Original.pdf to the filename try { var newName = this.path; var filename = newName.replace(".pdf","_Original.pdf"); this.saveAs(filename); for (var i = 0; i < this.numPages; i++) { numWords = this.getPageNumWords(i); if (numWords == 0) { // this page has no text, delete it this.deletePages(i,i); } } } catch(e) { app.alert(e); }


bottom of page