File | Date | Author | Commit |
---|---|---|---|
.DS_Store | 2017-12-18 |
![]() |
[4896da] First commit |
README.md | 2017-12-18 |
![]() |
[a77657] first commit |
rmpdfblanks.sh | 2017-12-18 |
![]() |
[4896da] First commit |
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
to a directory that is in your pathecho $PATH
/usr/local/bin/
in your path on OS X
~/.bash_profile
if it is not there alreadycpdf
to be able to run itchmod 744 /usr/local/bin/cpdf
cpdf -version
Usage:
cd "~/my/pdf's/directory"
rmpdfblanks.sh "my pdf.pdf"
$ 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
.