[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: PDF aus Images in einzelne Seiten zerlegen + OCR



Hallo Jakob,

> Steht Dein Script unter einer freien Lizenz, so dass ich es weiter
> verarbeiten darf?

Jetzt ja :-) So war es schon vorher gemeint. Siehe unten, v0.2.

Ich habe noch diverse Löschbefehle ergänzt, sonst werden evt. bei
Bearbeitung mehrerer PDFs falls in PDF 2 weniger Seiten als in 1 die
überschüssigen Seiten von 1 an 2 angehängt. Ausserdem Löschen der
unpaper-Splitfiles, sonst werden zweite Seiten bei einer Folgeseite mit
nur einer Seite ebenfalls angehängt.

Freundliche Grüße,
Christoph

#!/bin/bash

#
# Copyright (c) 2007 Christoph Conrad <mailto:christoph.conrad@gmx.de>
#
# pdfscanned2ascii v0.2
#
# Usage: pdfscanned2ascii <pdf-file>
#
# Split PDF consisting of scanned book images (two pages per image) and
# OCR the content. Output file: "<pdf-file>.txt".
#
# Required software: pdfimages, unpaper, convert, tesseract
#

#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#


# trap "" SIGINT

if [ "$1" == "" ]; then
    echo "Usage: $0 <pdf-file>"
    exit
fi

input="$1"
output="$1.txt"

rm -f images-*.ppm
rm -f images-*.pbm
rm -f image-split*

echo "split pdf to PPM/PBM (color/bw)"
pdfimages "$input" images

rm -f "$output"

find . -name 'images*' -type f -print | sort -n | while read file
do
   # split scanned double pages in single bw pages
   unpaper -t pbm --overwrite -l double -op 2 "$file" "image-split%d.pbm"

   # pbm->tiff
   convert image-split1.pbm image-split1.tiff
   convert image-split2.pbm image-split2.tiff

   # OCR & collect output
   tesseract image-split1.tiff out
   cat out.txt >> "$output"
   tesseract image-split2.tiff out
   cat out.txt >> "$output"

   rm -f image-split*
done



Reply to: