Paperyard
Public Member Functions | List of all members
pdfScanner Class Reference

takes PDFs and runs OCRmyPDF on them More...

Inheritance diagram for pdfScanner:
ppyrd

Public Member Functions

 __construct ($pdf, $db)
 constructor taking care of setup More...
 
 run ()
 function executing main logic More...
 
- Public Member Functions inherited from ppyrd
 __construct ($db)
 constructor More...
 
 checkCliVsWebserver ()
 
 output ($string, $debug=0)
 outputs string More...
 

Additional Inherited Members

- Public Attributes inherited from ppyrd
 $db
 

Detailed Description

takes PDFs and runs OCRmyPDF on them

Definition at line 10 of file ppyrd.scanner.php.

Constructor & Destructor Documentation

pdfScanner::__construct (   $pdf,
  $db 
)

constructor taking care of setup

Definition at line 15 of file ppyrd.scanner.php.

16  {
17  $this->pdf = $pdf;
18  $this->db = $db;
19  $this->tesseractCommand = $this->db->getConfigValue('tesseractCommand');
20  }

Member Function Documentation

pdfScanner::run ( )

function executing main logic

Definition at line 25 of file ppyrd.scanner.php.

26  {
27  $this->output("executing on " . $this->pdf);
28  // ensuring that we only have one OcrMyPDF running process running
29  // due to cron usage and large PDFs this could be an issue
30  $fp = fopen('/tmp/ppyrdOcrMyPdf.txt', 'w+');
31 
32  // checking if lock has been set properly
33  if(flock($fp, LOCK_EX))
34  {
35  // running OCRmyPDF
36  exec($this->tesseractCommand . " '" . $this->pdf . "' '/data/inbox/" . $this->pdf . "'");
37  if (file_exists("/data/inbox/" . $this->pdf))
38  {
39  // fixing user permissions since OCR is run as www-data
40  $this->output("fixing permissions");
41  exec ("user_id=$(stat -c '%u:%g' " . $this->pdf . '); chown $user_id /data/inbox/' . $this->pdf);
42  $this->output("found ok OCR - moving input to archive");
43  exec("mv --backup=numbered '" . $this->pdf . "' '/data/scan/archive/" . $this->pdf . "'");
44  } else
45  {
46  $this->output("did not find ok OCR - moving input to error");
47  exec("mv --backup=numbered '" . $this->pdf . "' '/data/scan/error/" . $this->pdf . "'");
48  }
49 
50  } else
51  {
52  // this will be echoed in case OCRmyPDF is still running
53  $this->output("OcrMyPdf still running - cannot interfere with it ... if this persists too long check /tmp/ppyrOcrMyPdf.txt and delete");
54  }
55 
56  // closing lock again - so other instances can be started.
57  fclose($fp);
58 
59  }
output($string, $debug=0)
outputs string
Definition: ppyrd.base.php:78

The documentation for this class was generated from the following file: