Browse Source

Update OcrTextFormatter.php

Addresses #988
pull/987/head
Rosie Le Faive 1 year ago committed by GitHub
parent
commit
4052cef24c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php

5
modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php

@ -132,8 +132,9 @@ class OcrTextFormatter extends FormatterBase implements ContainerFactoryPluginIn
$fileItem = $item->getValue();
$file = $this->entityTypeManager->getStorage('file')->load($fileItem['target_id']);
$contents = file_get_contents($file->getFileUri());
if (mb_detect_encoding($contents) != 'UTF-8') {
$contents = utf8_encode($contents);
$detected_encoding = mb_detect_encoding($contents);
if ($detected_encoding != 'UTF-8') {
$contents = mb_convert_encoding($contents, 'UTF-8', $detected_encoding);
}
$contents = nl2br($contents);
return $contents;

Loading…
Cancel
Save