Purpose
Pdf4split is a program that splits one page from PDF file into 4 JPEG files that can be easily printed as 4 distinct pages.
So in short it allows you to print a big page from PDF on 4 sheets of paper.
What you need additionally
In order to run this piece of software, you need:
- BASH interpreter
- gs — GhostScript processor
- ImageMagick
Each of these is installed (or can be easily installed) on most OS-es like Linux or Mac OS.
Download
just copy and paste into a text-file and set the "execute" bit. Then copy the file to /usr/bin (or similar).
#!/bin/bash
pdf="$1"
page="$2"
dpi="$3"
jpg="$pdf".jpg
jpg1="$pdf".1.jpg
jpg2="$pdf".2.jpg
jpg3="$pdf".3.jpg
jpg4="$pdf".4.jpg
if [ "$page" = "" ]; then
page=1
fi
if [ "$dpi" = "" ]; then
dpi=600
fi
if [ "$pdf" = "" ]; then
echo "Use: "
echo " $0 pdf-file"
echo " $0 pdf-file page-number"
echo " $0 pdf-file page-number dpi-resolution"
echo
echo "if page and dpi are not set, the first page is used"
echo "if dpi is not set, 600dpi is used"
exit 1
fi
echo "Converting PDF page $page to JPG with DPI $dpi"
gs -q -sDEVICE=jpeg -dBATCH -dNOPAUSE -dFirstPage="$page" -dLastPage="$page" -r"$dpi" -sOutputFile="$jpg" "$pdf"
echo "Identifying JPG"
wxh=`cat -- "$jpg" | identify - | awk '{print $3}' | sed 's/x/ /'`
w=`echo $wxh | awk '{print $1}'`
h=`echo $wxh | awk '{print $2}'`
w2=$((w/2))
h2=$((h/2))
dim=50%x50%
dim1=${dim}+0+0
dim2=${dim}+${w2}+0
dim3=${dim}+0+${h2}
dim4=${dim}+${w2}+${h2}
echo -n "Cropping image (4 times)"
convert "$jpg" -crop "$dim1" "$jpg1" && echo -n .
convert "$jpg" -crop "$dim2" "$jpg2" && echo -n .
convert "$jpg" -crop "$dim3" "$jpg3" && echo -n .
convert "$jpg" -crop "$dim4" "$jpg4" && echo ' OK'
How to use it
- First page:
$ pdf4split your-file.pdf
It will create 5 files:
- your-file.pdf.jpg — image of pdf
- your-file.pdf.1.jpg — left-top quarter of pdf
- your-file.pdf.2.jpg — right-top quarter of pdf
- your-file.pdf.3.jpg — left-bottom quarter of pdf
- your-file.pdf.4.jpg — right-bottom quarter of pdf
Print each file (fit the image on the sheet), and you're done!
- Fifth page:
$ pdf4split your-file.pdf 5
5 denotes fifth page. Files created as before.
- Custom DPI
In case you don't want to decode PDF in standard 600 DPI, you can specify custom one resolution.
300 would be just OK if you have 300 DPI printer and the PDF page is in A2 format (that is 2x2 x A4).
We use page 1 for this. (Note if you use DPI setting, you must explicitly set the page number too).
$ pdf4split your-file.pdf 1 300
When use it
This program is really useful when having PDFs with some electronic schemas and diagram meant to print on big format printers and you have only a standard A4. You can print it scaled down (and it will be hardly readable) or…
use pdf4split.
Hi, thats a very good script. Thank you very much for sharing
I didn't liked to setup an extra (virtual) Linux machine, because
So I decided to rewrite the script for Windows.
Here is it:
It is the same as the Linux version above, except the created files have slightly different names. I liked to have the page number within the filename.
It will create 5 files:
Note 1: the script creates 2 temporary files: your-scriptname.h, your-scriptname.w and deletes them if they aren't necessary any more
Note 2: script is not tested with filenames / directory names with blanks in the name.
Have fun!
JpgOrganizer
MBWE II (blue rings), 2x 1TB WD10EARS in Raid 1 mode
Firmware 01.01.18
Hacks: SSH, optware, spindown
Applications: dokuwiki, nightly backup script
I have no way to test that, because I have no Windows, but thanks for sharing! This may be useful for other people.
(This code reminded me coding in Atari BASIC, all those gotos, lol).
Piotr Gabryjeluk
visit my blog
Post preview:
Close preview