Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
README.md | 2017-12-20 | 3.2 kB | |
remove-pdf-blank-pages.zip | 2017-12-20 | 2.7 kB | |
rmpdfblanks.sh | 2017-12-19 | 1.9 kB | |
Totals: 3 Items | 7.8 kB | 1 |
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:
- From the PDF's directory, run the script with the filename
- Using
cpdf
, it then splits the PDF into individual pages into a temp directory - 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.
- Press a key and you will be transported to the temp directory (in
Finder
onOS X
), where you will sort the files by size, find the largest file that is a blank page, and note the size - Then enter a size slightly larger than this and press
Enter
and the script will find the non-blank pages and create a new PDF, usingcpdf
, with all the blank pages removed - 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:
- Download the version for your OS
- Scan it at VirusTotal Free Online Virus, Malware and URL Scanner
- Always scan anything you download from the net, including my script
- Copy
cpdf
to a directory that is in your path- To see your current path, type
echo $PATH
- You should have
/usr/local/bin/
in your path onOS 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
- To see your current path, type
- You have to change permissons for
cpdf
to be able to run itchmod 744 /usr/local/bin/cpdf
- To see if it runs type
cpdf -version
Usage:
- cd to the PDF's directory
cd "~/my/pdf's/directory"
rmpdfblanks.sh "my pdf.pdf"
- It is best to enclose the entire file name in double quotes in case there are spaces or special characters in the name
Sample output:
$ 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
.