Community

OCR a PDF file stored on Azure Blob Storage (ABBYY OCR Cloud) Answered

Need suggestion to OCR a PDF file stored on Azure Blob Storage. I want to OCR pdf file using Azure file link instead of downloading the file and passing its url to ABBYY OCR Cloud

Was this article helpful?

0 out of 0 found this helpful

Comments

3 comments

  • Avatar
    Marc Bachmann

    Hi Sajid,

    you don't need to create a new url to pass to the api.
    You can download the file and put it into the post-request directly.

    Best wishes

    Marc

    0
  • Avatar
    sajid.hussain

    Thank you for your support. Can you please explain your answer with some code snippet if possible. 

    0
  • Avatar
    Marc Bachmann

    sure.

    Download the file you want to convert and save it temporary to disc to use the following snippet. filepath + filename stored in $fillePath:

                $url = 'https://cloud.ocrsdk.com/processImage?language=german,latin,english&profile=textExtraction&exportFormat=xml';

                // Send HTTP POST request and ret xml response
                $curlHandle = curl_init();
                curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($curlHandle, CURLOPT_URL, $url);
                curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($curlHandle, CURLOPT_USERPWD, "$applicationId:$password");
                curl_setopt($curlHandle, CURLOPT_POST, 1);
                curl_setopt($curlHandle, CURLOPT_USERAGENT, "PHP Cloud OCR SDK Sample");
                curl_setopt($curlHandle, CURLOPT_FAILONERROR, true);
                $post_array = array();
                if((version_compare(PHP_VERSION, '5.5') >= 0)) {
                    $post_array["my_file"] = new \CURLFile($filePath);
                } else {
                    $post_array["my_file"] = "@".$filePath;
                }
                curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $post_array);
                $response = curl_exec($curlHandle);
                if($response == FALSE) {
                    $errortext = curl_error($curlHandle);
                    curl_close($curlHandle);
                    $error = true;
                }

    0

Please sign in to leave a comment.