Sometimes we need to edit the PDF files to make it suite our requirements. There are many tools available for it like pdfedit, pdfcrop, gpdftext etc. on Linux and lot other proprietary software in Windows.
I found editing with GIMP (GNU Image Manipulation Program) to be the best and easiest one, though it requires some hands-on with itself or Adobe Photoshop.
Steps
I found editing with GIMP (GNU Image Manipulation Program) to be the best and easiest one, though it requires some hands-on with itself or Adobe Photoshop.
Steps
- First open the PDF file with GIMP. You will see all the pages come as layers.
- Go to the particular layer you want to edit. Make changes using the various versatile tools available for editing.
- In my case I had to remove the white-space around the contents so that while printing the paper is fully utilised. For cropping you need to just crop the first layer and all the layers are cropped.
- Check the layers for accidental croppings.
- Save the file, exit from GIMP
- Now comes the interesting part. We need to save all the layers as separate images so that we can concat them to one pdf.
- We can do this by using this magnificent script. Before this script I was unaware that we can write scripts in GIMP. The author has done a great task.
- Following is the script if the links are broken
#!/usr/bin/env python
from gimpfu import *
from os.path import join
def save_all_layers(image, __unused_drawable, directory, name_pattern):
for layer in image.layers:
filename = join(directory, name_pattern % layer.name)
raw_filename = name_pattern % layer.name
pdb.gimp_file_save(image, layer, filename, raw_filename)
register(
"python_fu_save_all_layers",
"Save all layers into separate files",
"Save all layers into separate files",
"Lie Ryan",
"Lie Ryan",
"2012",
"/File/Save layers as images...",
"*",
[
(PF_DIRNAME, "directory", "Directory to put the images on", "/"),
(PF_STRING, "name_pattern", "Pattern for file name, %s will be replaced with layer name", "%s.png"),
],
[],
save_all_layers
)
main()
- Save the script in the folder ".gimp-X-X/plug-ins/save_all_layers.py
- Restart the GIMP and open the file.
- In the menu you will have a new entry "FILE>Save all layers into separate files"
- Add the required prefix, better add "page" as prefix. Give the folder where you want to save the images.
- Now using the convert tool on your Linux systems you need to change the images to a single pdf.
- For those who do not have convert installed run "sudo apt-get install imagemagick". It will install the related tools.
- Running "convert page*.png" mydoc.pdf will give the pages in incorrect order, the order will be same as that of the order in "ls" command. If the pages are more than 100 then it will create ordering issues in the pdf.
- For solving this find the maximum number of images files, and run the following script.
- #!/bin/sh
main() {
start=$1
end=$2
prefix=$3
ext=$4
output_file=$5
echo "convert --quality=100" > convert.sh
for i in `seq $start $end`; do
echo "$prefix$i.$ext" >> convert.sh
done
echo "$output_file" >> convert.sh
tr '\n' ' ' < convert.sh > convert2.sh
mv -f convert2.sh convert.sh
chmod 777 convert.sh
}
if [ "$#" != "5" ]; then
echo "Error in input"; echo "Usage -- START_NUMBER END_NUMBER PREFIX EXTENSION OUTPUT_FILE"
exit
else
main $1 $2 $3 $4 $5".pdf"
fi
- Save the following in any file, give it execute permission "chmod 777 gen_script.sh"
- call the script with proper inputs for example "./gen_script START_NUMBER END_NUMBER PREFIX EXTENSION OUTPUT_FILE"
- where
- START_NUMBER is the first page number
- END_NUMBER is the last page number
- PREFIX is the prefix of every file you gave in GIMP
- EXTENSION is the extension is the file extension of the images
- OUTPUT_FILE is the name of the pdf file you want to generate
- Example: ./gen_script.sh 1 210 page png mydoc.pdf
- You will get a script named convert.sh in your directory. You just need to run the script and you have the final edited pdf.