sub ApplyOCR{ my $TiffImageLocation = $_[0]; my $OCRResult; print "InitOnce : $InitOnce\n"; if ($InitOnce == 0) { $InitOnce = 1; #### To make it one time initialization $miDoc = Win32::OLE->new('MODI.Document') or die "Cannot create a MODI object"; print "miDoc : $miDoc\n"; } #### Creat the new document $miDoc->Create("$TiffImageLocation"); $miDoc->OCR(9,1,1); $miDoc->Save(); # print "Save object\n"; # print Dumper ($miDoc); # print "\n"; try{ my $ImageDoc = $miDoc->{Images}; if (defined $ImageDoc){ $OCRResult = $miDoc->{Images}->Item(0)->{Layout}{Text}; #### Close the opened document $miDoc->Close(); return $OCRResult; }else{ if ($DebugMsg == 1){ print "OCR cannot be done on this image in $TiffImageLocation\n"; #comment to debug- this is the message and } return 1; } }catch{ my $err = shift; warn "Some other kind of error in try: $err\n"; throw $err; if ($DebugMsg == 1){ print "OCR cannot be done on this image in $TiffImageLocation\n"; #comment to debug- this is the message and } return 1; } }