{"id":9193,"date":"2023-03-01T00:54:38","date_gmt":"2023-02-28T21:24:38","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/creating-a-pex-business-operation-1o2d\/"},"modified":"2023-03-01T00:54:38","modified_gmt":"2023-02-28T21:24:38","slug":"creating-a-pex-business-operation-1o2d","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/creating-a-pex-business-operation-1o2d\/","title":{"rendered":"\u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u0639\u0645\u0644\u06cc\u0627\u062a \u062a\u062c\u0627\u0631\u06cc PEX"},"content":{"rendered":"<div data-article-id=\"1382875\" id=\"article-body\">\n<p>PEX \u06cc\u06a9 \u0648\u06cc\u0698\u06af\u06cc \u062c\u062f\u06cc\u062f InterSystems IRIS \u0627\u0633\u062a \u06a9\u0647 \u0627\u0645\u06a9\u0627\u0646 \u06af\u0633\u062a\u0631\u0634 IRIS \u0631\u0627 \u0628\u0627 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0645\u0648\u062c\u0648\u062f \u0627\u0632 \u062c\u0627\u0648\u0627 \u06cc\u0627 \u062f\u0627\u062a \u0646\u062a \u0641\u0631\u0627\u0647\u0645 \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<p>\u0627\u06cc\u062c\u0627\u062f \u0642\u0627\u0628\u0644\u06cc\u062a \u0647\u0645\u06a9\u0627\u0631\u06cc \u0622\u062f\u0627\u067e\u062a\u0648\u0631\u0647\u0627\u06cc \u0648\u0631\u0648\u062f\u06cc \u0648 \u062e\u0631\u0648\u062c\u06cc\u060c \u062e\u062f\u0645\u0627\u062a \u062a\u062c\u0627\u0631\u06cc (\u0627\u062f\u063a\u0627\u0645 \u0627\u0632 \u062e\u0627\u0631\u062c\u06cc \u0628\u0647 \u062f\u0627\u062e\u0644\u06cc) \u0648 \u0639\u0645\u0644\u06cc\u0627\u062a (\u0627\u062f\u063a\u0627\u0645 \u062f\u0627\u062e\u0644\u06cc \u0628\u0647 \u062e\u0627\u0631\u062c\u06cc) \u0627\u0645\u06a9\u0627\u0646 \u067e\u0630\u06cc\u0631 \u0627\u0633\u062a.<\/p>\n<p>\u0628\u0631\u0627\u06cc \u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u06a9\u0627\u0645\u067e\u0648\u0646\u0646\u062a PEX \u0644\u0627\u0632\u0645 \u0627\u0633\u062a .NET (InterSystems.EnsLib.PEX) \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f.<em>) \u06cc\u0627 \u062c\u0627\u0648\u0627 (com.intersystems.enslib.pex.<\/em>) \u06a9\u0644\u0627\u0633 \u0645\u0646\u0627\u0633\u0628 \u0631\u0627 \u0628\u0633\u062a\u0647 \u0628\u0646\u062f\u06cc \u0648 \u06af\u0633\u062a\u0631\u0634 \u062f\u0627\u062f\u0647 \u06cc\u0627 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<p>\u062f\u0631 \u0627\u06cc\u0646 \u0645\u0642\u0627\u0644\u0647 \u0627\u0632 \u0633\u0631\u0648\u06cc\u0633 OCR \u062e\u0648\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u062e\u0648\u0627\u0647\u0645 \u06a9\u0631\u062f.  \u0627\u06cc\u0646 \u06cc\u06a9 \u0639\u0645\u0644\u06cc\u0627\u062a \u062a\u062c\u0627\u0631\u06cc PEX \u062f\u0627\u0631\u062f\u060c \u06a9\u062f \u0631\u0627 \u0628\u0628\u06cc\u0646\u06cc\u062f:<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>public class OcrOperation extends BusinessOperation {\n\n    \/\/ Connection to InterSystems IRIS\n    private IRIS iris;\n\n    @Override\n    public void OnInit() throws Exception {\n        iris = GatewayContext.getIRIS();\n    }\n\n    @Override\n    public Object OnMessage(Object request) throws Exception {\n        IRISObject req = (IRISObject) request;\n        String filePath = req.getString(\"FileName\");\n        String ocrText = doOcr(filePath);\n        IRISObject response = (IRISObject)(iris.classMethodObject(\"Ens.StringContainer\",\"%New\",ocrText));\n        return response;\n    }\n\n    public String doOcr(String filePath) {\n\n        File tempFile = new File(filePath);\n\n        String ocrText = \"\";\n\n        try {\n\n            if (tempFile.toString().contains(\".pdf\")) {\n                ocrText = extractTextFromPDF(tempFile);\n            } else {\n                ocrText = extractTextFromImage(tempFile);\n            }\n\n            return ocrText;\n\n        } catch (IllegalStateException | IOException | TesseractException e) {\n            return e.getMessage();\n        }\n\n    }\n\n    private String extractTextFromPDF(File tempFile) throws IOException, TesseractException {\n\n        String ocrText = \"\";\n\n        \/\/ Load file into PDFBox class\n        PDDocument document;\n        document = PDDocument.load(tempFile);\n\n        \/\/ Extract images from file\n        PDFRenderer pdfRenderer = new PDFRenderer(document);\n        StringBuilder out = new StringBuilder();\n\n        ITesseract tesseract = new Tesseract();\n        tesseract.setDatapath(\"\/usr\/share\/tessdata\/\"); \/\/directory to trained models \n        tesseract.setLanguage(\"por\"); \/\/ choose your language\/trained model\n\n        for (int page = 0; page &lt; document.getNumberOfPages(); page++) {\n            BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);\n\n            \/\/ Create a temp image file\n            File temp = File.createTempFile(\"tempfile_\" + page, \".png\");\n            ImageIO.write(bim, \"png\", temp);\n\n            String result = tesseract.doOCR(temp);\n            out.append(result);\n\n            \/\/ Delete temp file\n            Files.delete(temp.toPath());\n\n            ocrText = out.toString();\n        }\n\n        return ocrText;\n\n    }\n\n    private String extractTextFromImage(File tempFile) throws TesseractException {\n\n        ITesseract tesseract = new Tesseract();\n        tesseract.setDatapath(\"\/usr\/share\/tessdata\/\"); \/\/directory to trained models\n        tesseract.setLanguage(\"eng+por\"); \/\/ choose your language\/trained model\n\n        return tesseract.doOCR(tempFile); \/\/call tesseract function doOCR() \n                                          \/\/passing the file to be processed with OCR technique\n\n    }\n\n    @Override\n    public void OnTearDown() throws Exception {\n        \/\/ TODO Auto-generated method stub\n\n    }\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0628\u0631\u0627\u06cc \u0639\u0645\u0644\u06cc\u0627\u062a\u060c OnInit \u0631\u0627 \u0628\u0631\u0627\u06cc \u0634\u0631\u0648\u0639 \u0627\u062a\u0635\u0627\u0644 \u062c\u0627\u0648\u0627 \u0628\u0627 IRIS \u0648 \u062f\u0631 \u0635\u0648\u0631\u062a \u0644\u0632\u0648\u0645 \u0633\u0627\u06cc\u0631 \u0645\u0646\u0627\u0628\u0639 \u062c\u0627\u0648\u0627 \u0648 OnTearDown \u0631\u0627 \u0628\u0631\u0627\u06cc \u0627\u0646\u062a\u0634\u0627\u0631 \u0645\u0646\u0627\u0628\u0639 \u062a\u062e\u0635\u06cc\u0635 \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0627\u062c\u0631\u0627 \u0645\u06cc \u06a9\u0646\u06cc\u062f.  \u062f\u0631 \u0646\u0647\u0627\u06cc\u062a \u0628\u0627\u06cc\u062f OnMessage \u0631\u0627 \u0628\u0627 \u06a9\u062f \u0645\u0646\u0628\u0639 \u062e\u0648\u062f \u062f\u0631 \u0639\u0645\u0644\u06cc\u0627\u062a PEX \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u06a9\u0646\u06cc\u062f\u060c \u0627\u0632 \u062c\u0645\u0644\u0647 \u06a9\u062f\u06cc \u06a9\u0647 \u0627\u0632 \u0686\u0627\u0631\u0686\u0648\u0628 \u0647\u0627\u06cc \u062c\u0627\u0648\u0627 \u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0686\u06cc\u0632\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u062f\u060c \u062f\u0631 \u0645\u0648\u0631\u062f \u0645\u0646 \u0645\u0646\u0637\u0642\u06cc \u0628\u0631\u0627\u06cc \u0627\u0633\u062a\u062e\u0631\u0627\u062c \u0645\u062a\u0646 \u0627\u0632 \u062a\u0635\u0627\u0648\u06cc\u0631 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0686\u0627\u0631\u0686\u0648\u0628 Tess4J.  \u0627\u06cc\u0646 \u0686\u0627\u0631\u0686\u0648\u0628 \u0627\u0632 Google Tesseract \u0628\u0631\u0627\u06cc OCR \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<p>\u0628\u0631\u0627\u06cc \u0627\u06cc\u0646\u06a9\u0647 \u0627\u062a\u0635\u0627\u0644 \u062c\u0627\u0648\u0627 \u06a9\u0627\u0631 \u06a9\u0646\u062f\u060c \u0644\u0627\u0632\u0645 \u0627\u0633\u062a \u06cc\u06a9 \u062f\u0631\u0648\u0627\u0632\u0647 \u062c\u0627\u0648\u0627 \u0631\u0627 \u062f\u0631 \u062a\u0648\u0644\u06cc\u062f \u0628\u0627 \u0639\u0645\u0644\u06cc\u0627\u062a \u062a\u062c\u0627\u0631\u06cc \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f \u062a\u0627 \u0627\u062c\u0627\u0632\u0647 \u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u0632\u0645\u06cc\u0646\u0647 \u067e\u0631\u0648\u06a9\u0633\u06cc \u062c\u0627\u0648\u0627 \u0631\u0627 \u0628\u062f\u0647\u062f.  \u0646\u0645\u0648\u0646\u0647 \u062a\u0648\u0644\u06cc\u062f \u0645\u0646 \u0631\u0627 \u0628\u0628\u06cc\u0646\u06cc\u062f:<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>Class dc.ocr.OcrProduction Extends Ens.Production\n{\n\nXData ProductionDefinition\n{\n&lt;Production Name=\"dc.ocr.OcrProduction\" LogGeneralTraceEvents=\"false\"&gt;\n  &lt;Description&gt;&lt;\/Description&gt;\n  &lt;ActorPoolSize&gt;2&lt;\/ActorPoolSize&gt;\n  &lt;Item Name=\"OcrService\" Category=\"\" ClassName=\"dc.ocr.OcrService\" PoolSize=\"1\" Enabled=\"true\" Foreground=\"false\" Comment=\"\" LogTraceEvents=\"false\" Schedule=\"\"&gt; \n  &lt;\/Item&gt;\n  &lt;Item Name=\"JavaGateway\" Category=\"\" ClassName=\"EnsLib.JavaGateway.Service\" PoolSize=\"1\" Enabled=\"true\" Foreground=\"false\" Comment=\"\" LogTraceEvents=\"false\" Schedule=\"\"&gt;\n    &lt;Setting Target=\"Host\" Name=\"ClassPath\"&gt;.:\/usr\/irissys\/dev\/java\/lib\/JDK18\/*:\/opt\/irisapp\/*:\/usr\/irissys\/dev\/java\/lib\/gson\/*:\/usr\/irissys\/dev\/java\/lib\/jackson\/*:\/jgw\/ocr-pex-1.0.0.jar&lt;\/Setting&gt; \n    &lt;Setting Target=\"Host\" Name=\"JavaHome\"&gt;\/usr\/lib\/jvm\/java-8-openjdk-amd64\/&lt;\/Setting&gt; \n  &lt;\/Item&gt; \n  &lt;Item Name=\"OcrOperation\" Category=\"\" ClassName=\"EnsLib.PEX.BusinessOperation\" PoolSize=\"1\" Enabled=\"true\" Foreground=\"false\" Comment=\"\" LogTraceEvents=\"false\" Schedule=\"\"&gt; \n    &lt;Setting Target=\"Host\" Name=\"%gatewayPort\"&gt;55555&lt;\/Setting&gt; \n    &lt;Setting Target=\"Host\" Name=\"%remoteClassname\"&gt;community.intersystems.pex.ocr.OcrOperation&lt;\/Setting&gt; \n    &lt;Setting Target=\"Host\" Name=\"%gatewayExtraClasspaths\"&gt;.:\/usr\/irissys\/dev\/java\/lib\/JDK18\/*:\/opt\/irisapp\/*:\/usr\/irissys\/dev\/java\/lib\/gson\/*:\/usr\/irissys\/dev\/java\/lib\/jackson\/*:\/jgw\/ocr-pex-1.0.0.jar&lt;\/Setting&gt; \n  &lt;\/Item&gt; \n&lt;\/Production&gt;\n}\n\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0645\u0647\u0645 \u0627\u0633\u062a \u06a9\u0647 \u0645\u0633\u06cc\u0631 \u06a9\u0644\u0627\u0633 \u0631\u0627 \u0628\u0647 Java JAR \u06a9\u0647 \u062a\u0648\u0633\u0637 \u0628\u0631\u0646\u0627\u0645\u0647 Java PEX \u0634\u0645\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc\u200c\u0634\u0648\u062f\u060c \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f \u0648 \u067e\u0648\u0631\u062a \u0648 \u0646\u0627\u0645 \u06a9\u0644\u0627\u0633 Java PEX \u0635\u062d\u06cc\u062d \u0631\u0627 \u062a\u0646\u0638\u06cc\u0645 \u06a9\u0646\u06cc\u062f.<\/p>\n<p>\u062a\u0645\u0627\u0645 \u062c\u0632\u0626\u06cc\u0627\u062a \u0631\u0627 \u062f\u0631 github \u0628\u0647 \u0633\u0631\u0648\u06cc\u0633 OCR \u0645\u0646 \u0645\u0634\u0627\u0647\u062f\u0647 \u06a9\u0646\u06cc\u062f.  \u0645\u06cc \u062a\u0648\u0627\u0646 \u0627\u0632 \u0622\u0646 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0646\u0642\u0637\u0647 \u0634\u0631\u0648\u0639 \u0628\u0631\u0646\u0627\u0645\u0647 PEX \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f.<\/p>\n<p>https:\/\/openexchange.intersystems.com\/package\/OCR-Service <\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>PEX \u06cc\u06a9 \u0648\u06cc\u0698\u06af\u06cc \u062c\u062f\u06cc\u062f InterSystems IRIS \u0627\u0633\u062a \u06a9\u0647 \u0627\u0645\u06a9\u0627\u0646 \u06af\u0633\u062a\u0631\u0634 IRIS \u0631\u0627 \u0628\u0627 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0645\u0648\u062c\u0648\u062f \u0627\u0632 \u062c\u0627\u0648\u0627 \u06cc\u0627 \u062f\u0627\u062a \u0646\u062a \u0641\u0631\u0627\u0647\u0645 \u0645\u06cc \u06a9\u0646\u062f. \u0627\u06cc\u062c\u0627\u062f \u0642\u0627\u0628\u0644\u06cc\u062a \u0647\u0645\u06a9\u0627\u0631\u06cc \u0622\u062f\u0627\u067e\u062a\u0648\u0631\u0647\u0627\u06cc \u0648\u0631\u0648\u062f\u06cc \u0648 \u062e\u0631\u0648\u062c\u06cc\u060c \u062e\u062f\u0645\u0627\u062a \u062a\u062c\u0627\u0631\u06cc (\u0627\u062f\u063a\u0627\u0645 \u0627\u0632 \u062e\u0627\u0631\u062c\u06cc \u0628\u0647 \u062f\u0627\u062e\u0644\u06cc) \u0648 \u0639\u0645\u0644\u06cc\u0627\u062a (\u0627\u062f\u063a\u0627\u0645 \u062f\u0627\u062e\u0644\u06cc \u0628\u0647 \u062e\u0627\u0631\u062c\u06cc) \u0627\u0645\u06a9\u0627\u0646 \u067e\u0630\u06cc\u0631 \u0627\u0633\u062a. \u0628\u0631\u0627\u06cc \u0627\u06cc\u062c\u0627\u062f \u06cc\u06a9 \u06a9\u0627\u0645\u067e\u0648\u0646\u0646\u062a PEX \u0644\u0627\u0632\u0645 \u0627\u0633\u062a .NET &hellip;<\/p>\n","protected":false},"author":2,"featured_media":9195,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-9193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/9193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=9193"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/9193\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/9195"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=9193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=9193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=9193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}