Help for my program

Hello

can someone help me, we have a program that we use to read in scanned documents. it is working but we have a problem. the guy how has program this, is not working anymore in our company. my knowledge about this program language is to little.

First what the program do is. we scan PDF documents to the server, the document is waiting their till we run this program.

when we run the program the program is looking for an combination two letters an 6 numbers. that’s our ordernumber. the hole system is working okay, but we have a little problem sometimes. one of our order is beginning with IC. when we read the ordernumber in the PDF he see the I as a 1 (one) and there it goes wrong. can anyone help me ?

program

 

$inputlocation = “\VRCFS022.VDLGROEP.LOCAL\VDLGROEP2$\VIP\Algemeen\LogistixScanData”;
$savelocation = “\VRCFS022.VDLGROEP.LOCAL\VDLGROEP2$\VIP\Archief\LogistixImportData”;
$shortcutlocation = “\VRCAS082.VDLGROEP.LOCAL\Algemeen$\Dosyslog”;

$idpattern = ‘[iI][bBcCgGkKlLnNpPrRtTxX][\d]{6}’;

Add-Type -Path “D:\Logistix\Batch_programmas\itextsharp.dll”

function CreateShortcut {
Param($sourcefile, $destenationpath)

echo “–CreateShortcut()–”;
$shortcutpath = $destenationpath + “.lnk”;
echo “s> s> $sourcefile”;
echo “s> d> $shortcutpath”;

$Shell = New-Object -ComObject (“WScript.Shell”);
$ShortCut = $Shell.CreateShortcut($shortcutpath);
$ShortCut.TargetPath=$sourcefile;
$ShortCut.Save();

echo “–!CreateShortcut()–”;
}

function searchIDinPDF
{
Param($sourcefile)

prepare the pdf

$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $sourcefile

$logistixid = $null

for each page

for($page = 1; $page -le $reader.NumberOfPages; $page++) {

set the page text

$pageText = [iTextSharp.text.pdf.parser.PdfTextExtractor]::GetTextFromPage($reader,$page).Split([char]0x000A)

if the page text contains any of the keywords we’re evaluating

$match = [regex]::Match($pageText, $idpattern ).captures
if($match)
{
foreach ($m in $match)
{
$logistixid = $m.value.ToUpper()
break;
}
}
}
$reader.Close()

return $logistixid
}

Get-ChildItem $inputlocation |
Foreach-Object {

$name = $.Name
$file = $name.substring(0,2).toupper() + $name.substring(2)
$fullname = $
.FullName

echo “----->File $file <-------”

if($file -match ‘^(P[A-Z]\d{6}|R[A-Z]\d{6}|R-\d{6}_)’)
{
$folder = “Inkooporder\document”;
$cat = “LeverancierOrderBev”;

echo “Move to inkooporder”
$filelocation = $savelocation + $folder + $file;
$destenationpath = $shortcutlocation + $folder + $file;

echo “F> $filelocation”
echo “S> $destenationpath”
Move-Item -Path $fullname -Destination $filelocation
CreateShortcut $filelocation $destenationpath ;
}
elseif($file -match ‘^U-\d{6}_’)
{
$folder = “Productieorder\document”;

echo “Move to Productieorder $logistixId”
$filelocation = $savelocation + $folder + $file;
$destenationpath = $shortcutlocation + $folder + $file;

echo “F> $filelocation”
echo “S> $destenationpath”
Move-Item -Path $fullname -Destination $filelocation
CreateShortcut $filelocation $destenationpath ;
}
elseif($file -match ‘^IO\d{6}_’)
{
$folder = “Offerte\document”;

echo “Move to Offerte”
$filelocation = $savelocation + $folder + $file;
$destenationpath = $shortcutlocation + $folder + $file;

echo “F> $filelocation”
echo “S> $destenationpath”
Move-Item -Path $fullname -Destination $filelocation
CreateShortcut $filelocation $destenationpath ;
}
elseif($file -match ‘^I[A-Z]\d{6}|^A[A-Z]\d{6}’)
{
$folder = “Verkooporder\document”;

echo “Move to Verkooporder”
$filelocation = $savelocation + $folder + $file;
$destenationpath = $shortcutlocation + $folder + $file;

echo “F> $filelocation”
echo “S> $destenationpath”
Move-Item -Path $fullname -Destination $filelocation
CreateShortcut $filelocation $destenationpath ;
}
elseif($file -match ‘^AutoV_’)
{
echo “Found> Auto verkoop order”
$folder = “Verkooporder\document”;
$logistixid = searchIDinPDF $fullname

if($logistixid)
{
echo “ID founded”
echo “Logistix ID> $logistixid”
$name = $name.replace(“AutoV”,$logistixid)
echo “Name> $name”
Rename-Item -Path $fullname -NewName $name
$fullname = $fullname.replace(“AutoV”,$logistixid)

echo “Move to Verkooporder”
$filelocation = $savelocation + $folder + $name;
$destenationpath = $shortcutlocation + $folder + $name;

echo “F> $filelocation”
echo “S> $destenationpath”
Move-Item -Path $fullname -Destination $filelocation

CreateShortcut $filelocation $destenationpath ;
}
else
{
echo “no ID founded”
}
}

else
{
echo “no match”
}
}

echo “-------------Einde script-------------”;

 

 

Formatting you code definitely helps anybody trying to help you :slight_smile: . Please look at the code formatting guidelines https://powershell.org/forums/topic/guide-to-posting-code-2/

thanks i close this topic, i have found other solution

Awesome. Will it be possible for you to share the solution. It might help somebody in future :slight_smile: