use strict;
use warnings;
use CAM::PDF;
use LWP::UserAgent;
my $pdf_filename = 'C:\Users\Jay\Desktop\SBS DEV\test.pdf';
convert_pdf_to_text();
sub convert_pdf_to_text {
use CAM::PDF::PageText;
my $pdf_filename = 'C:\Users\Jay\Desktop\SBS DEV\test.pdf';
my $pdf = CAM::PDF->new($pdf_filename);
my $y = $pdf->getPageContentTree(1);
print CAM::PDF::PageText->render($y);
}
####
use strict;
use warnings;
use DBI;
use CAM::PDF;
my $db;
my $sql;
my $src;
my $tgt;
my $file;
my $cnt;
my @row;
sub ConvertPDFToText
{
my $infn;
my $fh;
my $pdf;
my $content;
$infn = "$_[0]\\$_[2]";
open($fh, '>',"$_[1]" . "\\" . "Archive.txt");
print "filename $infn\n";
print "xx\n";
$pdf = CAM::PDF->new($infn);
$content = $pdf->getPageContentTree(1);
print CAM::PDF::PageText->render($content);
return "";
}
#Get db handle;
$db = DBI->connect('DBI:mysql:SBS_Dev', 'DBProcess','ThhuSd73MIWAWaY6') or die 'Cant Connect to DB';
# Get file directories
$sql = $db->prepare('SELECT SRC_DIR, TGT_DIR FROM EXP_EXTRACT_CNTL WHERE ID = 1') or die 'Couldnt run cntl sql: '. $db->errstr;
$sql->execute();
@row = $sql->fetchrow_array();
($src, $tgt) = @row;
print "source $src\n";
print "target $tgt\n";
if ($sql->rows == 0)
{
die 'Control info not found';
}
#Process Files from Source Directory
opendir(DIR, $src) or die "Cant open Dir: $!";
while (($file = readdir(DIR)))
{
if ($file ne '.' and $file ne '..' and $file ne "Archive")
{
print "file $file\n";
#get data out of file
ConvertPDFToText($src, $tgt, $file);
$cnt = $cnt + 1;
# Move file to archive
rename "$src\\$file" => "$tgt\\$file";
}
}
closedir(DIR);
print '$cnt files processed\n';
####
C:\Users\Jay\Desktop\SBS DEV\CODE\perl>.\sbsextractfrompdf.pl
source C:\Users\Jay\Desktop\SBS DEV\Data\Receipts
target C:\Users\Jay\Desktop\SBS DEV\Data\Extracted
file home depot large 2.pdf
filename C:\Users\Jay\Desktop\SBS DEV\Data\Receipts\home depot large 2.pdf
xx
Can't locate object method "render" via package "CAM::PDF::PageText" at C:\Users
\Jay\Desktop\SBS DEV\CODE\perl\SBSExtractFromPDF.pl line 31.
C:\Users\Jay\Desktop\SBS DEV\CODE\perl>