Menu

Tree [a77657] master /
 History

HTTPS access


File Date Author Commit
 .DS_Store 2017-12-18 PacoH PacoH [4896da] First commit
 README.md 2017-12-18 PacoH PacoH [a77657] first commit
 rmpdfblanks.sh 2017-12-18 PacoH PacoH [4896da] First commit

Read Me

Remove-PDF-Blank-Pages

Bash script to remove blank pages from a PDF

Very fast and simple to use

The way it works is very simple:
1. From the PDF's directory, run the script with the filename
2. Using cpdf, it then splits the PDF into individual pages into a temp directory
3. It then prompts you with some simple instructions that tell you to
* Arrange files by size: (OS X Finder: ⌃-⌘-6).
* Find the largest file with a blank page and note the size of the file in bytes.
* Enter that file size, in bytes, plus 500 to 1000, at the prompt.
4. Press a key and you will be transported to the temp directory (in Finder on OS X), where you will sort the files by size, find the largest file that is a blank page, and note the size
5. Then enter a size slightly larger than this and press Enter and the script will find the non-blanks pages and create a new PDF, using cpdf, with all the blank pages removed
6. It will open the PDF in your reader and remove the temp directory

I wrote the script for OS X, but the core code should work on any platform's bash shell. There may be some lines that are OS X-specific and would need to be changed for other platforms. Please submit a fork for your platform if you do.

Requires:

cpdf

  1. Download the version for your OS
  2. Scan it at VirusTotal Free Online Virus, Malware and URL Scanner
  3. Always scan anything you download from the net, including my script
  4. Copy cpdf to a directory that is in your path
  5. To see your current path, type echo $PATH
    • You should have /usr/local/bin/ in your path on OS X
    • This is the preferred path to copy it to
    • You'll have to create the directory and add it to your path, permanently, through ~/.bash_profile if it is not there already
    • You should be able to find out how to do this, online
  6. You have to change permissons for cpdf to be able to run it
  7. chmod 744 /usr/local/bin/cpdf
  8. To see if it runs type cpdf -version

Usage:

  1. cd to the PDF's directory
  2. cd "~/my/pdf's/directory"
  3. rmpdfblanks.sh "my pdf.pdf"
  4. It is best to enclose the entire file name in double quotes in case there are spaces or special characters in the name
$ rmpdfblanks.sh "my pdf.pdf"

Splitting PDF into pages…

Find minimum file size after pressing any key:

1. Arrange files by size: (OS X Finder: ⌃-⌘-6).
2. Find the largest file with a blank page and note the size of the file in bytes.
3. Enter that file size, in bytes, plus 500 to 1000, at the prompt.

Press any key to go to **pages** directory...

Maximum file size to remove, in bytes––any files <= this size will be removed: (0 default for no blank pages) 7000

**443 total pages - 218 blank pages ––> 225 non-blank pages**

Removing 218 blank pages…

real    0m57.088s
user    0m1.131s
sys     0m0.700s

The file was 98.6 MB and had 442 pages with 218 blank pages.
The entire operation took 0m57.088s, including opening the pages directory, sorting by size in descending order, and identifying the blank page file of largest size. Already knowing the size, it took just 0m21.136s.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.