Difference between revisions of "Split A3 PDF into A4 PDF (down the middle)"

From n0r1sk software solutions
Jump to: navigation, search
Line 8: Line 8:
  
 
If you like the software, leave us an email or make a donation!
 
If you like the software, leave us an email or make a donation!
 +
 +
== SCRIPT EDITION ==
  
 
== Install the needed packages ==
 
== Install the needed packages ==

Revision as of 18:38, 15 May 2011

This article describes how to create one DIN A4 PDF (with 2 or more pages) out of one DIN A3 PDF. The source A3 PDF is splitted down the middle. In the output PDF the pages are sorted. See the example PDF files.

JAVA GUI EDITION

Well, I've done a JAVA gui edition of this software. You can start it via Java Web Start by clicking the following link A3to2A4 Converter.

Please be patient, I an not a developer so this software is, I would say, a rough hack. If you would like to get the source code, please send us an email!

If you like the software, leave us an email or make a donation!

SCRIPT EDITION

Install the needed packages

At first you have to install the right packages which are needed for the converting script. (Debian example)

  • pdfinfo (in package poppler-utils)
  • bc (commandline calculator)
  • gs (ghostscript)
  • pdftk (pdf manipulation tool)
apt-get update
apt-get install poppler-utils ghostscript bc

Create the Script

We have to create the script, which converts the PDF. I'll name it "convert_pdf.sh".

#!/bin/bash

WIDTH=`pdfinfo $1 | head -n 5 | tail -n 1 | awk '{ print $3 }'`
HEIGHT=`pdfinfo $1 | head -n 5 | tail -n 1 | awk '{ print $5 }'`
PAGES=`pdfinfo $1 | head -n 3 | tail -n 1 | awk '{ print$2 }'`

WIDTH2=`echo "$WIDTH/2" | bc`
WIDTH3=$WIDTH2"0"

HEIGHTFULL=`echo "$HEIGHT*10" | bc`
SIZEFULL="-g"$WIDTH3"x"$HEIGHTFULL

echo $WIDTH2
echo $SIZEFULL
echo $HEIGHT

gs -o left-sections.pdf -sDEVICE=pdfwrite -sPAPERSIZE=a4 $SIZEFULL -c "<</PageOffset [0 0]>> setpagedevice" -f $1

gs -o right-sections.pdf -sDEVICE=pdfwrite -sPAPERSIZE=a4 $SIZEFULL -c "<</PageOffset [-$WIDTH2 0]>> setpagedevice" -f $1

SORT=""
PAGE="1"

while [ $PAGE -le $PAGES ]
do
        SORT=$SORT"A"$PAGE" B"$PAGE" "
        PAGE=$[$PAGE+1]
done

echo $SORT

pdftk A=left-sections.pdf B=right-sections.pdf cat $SORT output $1_finish.pdf  verbose

rm left-sections.pdf
rm right-sections.pdf

Test the script

So, time has come to test the script above!  :)

./convert_pdf.sh example.pdf

The output should be one PDF with the name "example_finish.pdf" including two DIN A4 pages.

Example Files