diff --git a/azure-ocr-service/azure-ocr-service-processor/src/main/java/com/knecon/fforesight/service/ocr/processor/service/imageprocessing/GhostScriptService.java b/azure-ocr-service/azure-ocr-service-processor/src/main/java/com/knecon/fforesight/service/ocr/processor/service/imageprocessing/GhostScriptService.java index 25ee225..65b4669 100644 --- a/azure-ocr-service/azure-ocr-service-processor/src/main/java/com/knecon/fforesight/service/ocr/processor/service/imageprocessing/GhostScriptService.java +++ b/azure-ocr-service/azure-ocr-service-processor/src/main/java/com/knecon/fforesight/service/ocr/processor/service/imageprocessing/GhostScriptService.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import org.springframework.stereotype.Service; @@ -15,14 +16,12 @@ import com.knecon.fforesight.service.ocr.processor.model.ImageFile; import com.knecon.fforesight.service.ocr.processor.model.PageBatch; import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.experimental.FieldDefaults; import lombok.extern.slf4j.Slf4j; @Slf4j @Service -@RequiredArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @SuppressWarnings("PMD") // can't figure out how to safely close the stdOut and stdError streams in line 72/74 public class GhostScriptService { @@ -34,6 +33,37 @@ public class GhostScriptService { private Semaphore concurrencySemaphore = new Semaphore(3); + public GhostScriptService(OcrServiceSettings ocrServiceSettings) { + + this.ocrServiceSettings = ocrServiceSettings; + assertGhostscriptIsInstalled(); + } + + + private void assertGhostscriptIsInstalled() { + + try { + Process p = Runtime.getRuntime().exec("gs -v"); + InputStream stdOut = p.getInputStream(); + InputStream errOut = p.getErrorStream(); + assert p.waitFor(1, TimeUnit.SECONDS); + log.info("Ghostscript is installed."); + String out = new String(stdOut.readAllBytes()); + String error = new String(errOut.readAllBytes()); + for (String line : out.split("\n")) { + log.info(line); + } + if (!error.isBlank()) { + log.error(error); + } + } catch (Exception e) { + log.error("Ghostscript is not installed!"); + log.error(e.getMessage(), e); + throw new RuntimeException(e); + } + } + + @SneakyThrows public void startBatchRender(PageBatch batch, ImageProcessingSupervisor supervisor, Consumer successHandler, Consumer errorHandler) { diff --git a/azure-ocr-service/azure-ocr-service-server/src/main/resources/Aptfile b/azure-ocr-service/azure-ocr-service-server/src/main/resources/Aptfile index 6ee2eb0..a611fbc 100644 --- a/azure-ocr-service/azure-ocr-service-server/src/main/resources/Aptfile +++ b/azure-ocr-service/azure-ocr-service-server/src/main/resources/Aptfile @@ -1,5 +1,5 @@ # you can list packages -ghostscript=9.55.0~dfsg1-0ubuntu5.9 +ghostscript=9.55.0~dfsg1-0ubuntu5.10 pkg-config zip unzip