I am redact a lot of PDF files everyday, so I spend a lot of time thinking how to do it the best way.
For me the best way is split PDF in 1-page PDF file, next to edit with GIMP, next to combine it. I don't use imagemagick on all files (I do not use at all), so I don't loss text-layer on all pages, but only on redacted. Do not load the whole PDF file at once, because it causes memory exhaustion.
Split PDF in 1-page files
Easily split PDF files to 1-page PDF you can by this bash function (put it in ~/.bashrc):
function pdf_split(){
for file in "$@"; do
if [ "${file##*.}" != "pdf" ]; then
echo "Skip $file because it's not PDF file";
continue
fi;
pages=$(pdfinfo "$file" | grep "Pages" | awk '{print $2}')
echo "Detect $pages in $file";
filename="${file%.*}";
unset Outfile;
for i in $(seq 1 "$pages"); do
pdftk "$file" cat "$i" output "$filename-$i.pdf";
Outfile[$i]="$filename-$i.pdf";
done;
done;
};
You can now enter split_pdf file.pdf
to get a lot of PDF files.
Redact files
But, now you need edit all this files.
You can do it with gimp original-filename-*.pdf
.
I suggest configure shortcut in GIMP (Main window->Edit-> Shortcut) to replace file (I use CTRL+R), blur filter (eg. CTRL+D), close file (eg. CTRL+W) and exit GIMP (eg.CTRL+Q). Remember to don't load in GIMP to many files at once, but GIMP as you about load after open, so you can use gimp original-filename-*.pdf
on thousand files safe.
Combine files
You can combine files easily with: pdftk originam-filename-*.pdf cat output "new-file-anon.pdf";
Connect it all together
These operations are very repetitive and boring, so I connect it all in 1 script:
function pdf_redact(){
for file in "$@"; do
if [ "${file##*.}" != "pdf" ]; then
echo "Skip $file because it's not PDF file";
continue
fi;
pages=$(pdfinfo "$file" | grep "Pages" | awk '{print $2}')
echo "Detect $pages in $file";
filename="${file%.*}";
unset Outfile;
for i in $(seq 1 "$pages"); do
pdftk "$file" cat "$i" output "$filename-$i.pdf";
Outfile[$i]="$filename-$i.pdf";
done;
gimp "${Outfile[@]}";
pdftk "${Outfile[@]}" cat output "$filename-anon.pdf";
rm "${Outfile[@]}";
read -p "Do you want open output file? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
evince "$filename-anon.pdf";
fi
read -p "Do you want upload output file to Scribd.com? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
scribd_up "$filename-anon.pdf";
fi
done;
};
The newest version of this script is always accessible at: http://dostep.jawne.info.pl/it/bashrc
Remember to close GIMP (CTRL+Q) after all redaction to continue script.
In addiction it as me to open redacted files (I like read to check whether all) and as to upload to Scribd with my other script - scribd_up, so now I can redact a lot of PDF files very efficiently.