Commit a2db449e authored by Alex ORLUC's avatar Alex ORLUC
Browse files

Merge branch 'fix/17658/reconcile_multiple_page' into '1.8'

FIX #17658 TIME 2 convert first page pdf to img for qrcode

See merge request maarch/MaarchCapture!25
parents 3d9d30f0 1bcd980c
......@@ -54,7 +54,7 @@ class QRSeparator
foreach ($files as $key => $value) {
$array_files = explode('.', $files[$key]);
//Ignore all files except pdf
// Ignore all files except pdf
if (strtolower($array_files[1]) == 'pdf') {
echo "\n\n * File n°".$num_file.": ".$files[$key]." *\n";
$_SESSION['capture']->logEvent(
......@@ -64,7 +64,8 @@ class QRSeparator
try {
copy($ScanSource.$files[$key], $this->Batch->directory . '/' . $key . '.pdf');
echo "process file n°".$this->Batch->directory . '/' . $key . '.pdf'. PHP_EOL;
//Attempt to extract QRCODE
// Attempt to extract QRCODE
try {
$qrcode = new \Zxing\QrReader($this->Batch->directory . '/' . $key.'.pdf');
} catch (Exception $e) {
......@@ -75,7 +76,35 @@ class QRSeparator
return false;
}
$text = $qrcode->text();
try {
$text = $qrcode->text();
} catch (Exception $e) {
$text = false;
}
if ($text === false) {
// If library fails to read qr code in pdf, we try to read it with a different method by converting the pdf to an image
exec('convert -density 150 ' . $this->Batch->directory . '/' . $key.'.pdf[0] -colorspace RGB ' . $this->Batch->directory . '/' . $key . '.png');
$imageFileFirstPage = $this->Batch->directory . '/' . $key . '.png';
exec('zbarimg ' . $imageFileFirstPage, $resultZbar);
if (!empty($resultZbar)) {
$textExploded = explode(':', $resultZbar[0]);
if (is_array($textExploded) && $textExploded[0] <> 'QR-Code') {
// echo 'NO QR CODE' . PHP_EOL;
$text = '';
} else {
$text = str_replace('QR-Code:', '', $resultZbar[0]);
}
} else {
// echo "NO RESULT";
$text = '';
}
}
echo 'qrcode : ' . $text . PHP_EOL;
$data = json_decode($text, true);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment