#!/usr/bin/perl -w
# 
# pdf-Dateien suchen, nach text umwandeln und in eine Datenbank einfügen. 
# 
# Author: Peter Keel
# Last-Modified: 26.05.2004
# License: Public Domain

use DBI;

$DB_HOST="localhost";
$DB_DATABASE="";
$DB_PORT="3306";
$DB_USER="";
$DB_PASSWORD="";
$tempfile="/home/user/pdfindex.temp";
$connectionInfo="DBI:mysql:database=$DB_DATABASE;$DB_HOST:$DB_PORT";

$dbh = DBI->connect($connectionInfo,$DB_USER,$DB_PASSWORD);

    $query = "truncate tbl_search_pdf";
    $sth = $dbh->prepare($query);
    $sth->execute();
    $sth->finish();

  chomp(@pdfs = qx!/usr/bin/find ./htdocs -name *.pdf -print | grep -v gremien | grep -v webEdition!);
    foreach $pdf (@pdfs) {
	system ("/usr/bin/pdftotext $pdf $tempfile");
	chomp($pdfcontent = qx!/bin/cat $tempfile!);
	$pdfcontent =~ s/'//g;
	$query = "INSERT INTO tbl_search_pdf (Path, Text) VALUES ('$pdf', '$pdfcontent')";
	$sth = $dbh->prepare($query);
	$sth->execute();
	print STDOUT "Inserted $pdf\n";
    }

$sth->finish();

$dbh->disconnect; 

unlink($tempfile);
