From aabb3538e4ceb7db746614f7cfb01c7a91ce755f Mon Sep 17 00:00:00 2001 From: Dantist Date: Sun, 11 Jun 2017 04:31:47 +0300 Subject: [PATCH] Added an ability to perform OCR via API --- README.md | 24 ++++++++++++++++++++++++ src/Convertio.php | 12 +++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57e6684..7a204fc 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,30 @@ Following example will override default API parameters in case you don't have SS $API->startFromURL('http://google.com/', 'png')->wait()->download('./google.png')->delete(); ``` +OCR Quickstart +------------------- +Following example will convert pages 1-3,5,7 of PDF into editable DOCX, using OCR (Optical Character Recognition) for English and Spanish languages (Full list of available languages): +```php +start('./test.pdf', 'docx', // Convert PDF (which contain scanned pages) into editable DOCX + [ // Setting Conversion Options (Docs: https://convertio.co/api/docs/#options) + 'ocr_enabled' => true, // Enabling OCR + 'ocr_settings' => [ // Defining OCR Settings + 'langs' => ['eng','spa'], // OCR language list (Full list: https://convertio.co/api/docs/#ocr_langs) + 'page_nums' => '1-3,5,7' // Page numbers to process (optional) + ] + ] + ) + ->wait() // Wait for conversion finish + ->download('./test.docx') // Download Result To Local File + ->delete(); // Delete Files from Convertio hosts +``` + Installation ------------------- You can use **Composer** or simply **Download the Release** diff --git a/src/Convertio.php b/src/Convertio.php index a0ed794..7f991d7 100644 --- a/src/Convertio.php +++ b/src/Convertio.php @@ -187,6 +187,7 @@ public function rawStart($data) * * @param string $input_fn path to local input file * @param string $output_format output format. You can view available formats on https://convertio.co/formats/ + * @param array $options conversion options. You can view available options on https://convertio.co/api/docs/ * @return \Convertio\Convertio * * @throws \Exception @@ -194,11 +195,12 @@ public function rawStart($data) * @throws \Convertio\Exceptions\CURLException if there is a general HTTP / network error * */ - public function start($input_fn, $output_format) + public function start($input_fn, $output_format, $options = array()) { $data = array(); $data['input'] = 'upload'; $data['outputformat'] = $output_format; + $data['options'] = $options; $this->rawStart($data); @@ -223,6 +225,7 @@ public function start($input_fn, $output_format) * * @param string $url URI of input file or web-page * @param string $output_format output format. You can view available formats on https://convertio.co/formats/ + * @param array $options conversion options. You can view available options on https://convertio.co/api/docs/ * @return \Convertio\Convertio * * @throws \Exception @@ -230,12 +233,13 @@ public function start($input_fn, $output_format) * @throws \Convertio\Exceptions\CURLException if there is a general HTTP / network error * */ - public function startFromURL($url, $output_format) + public function startFromURL($url, $output_format, $options = array()) { $data = array(); $data['input'] = 'url'; $data['file'] = $url; $data['outputformat'] = $output_format; + $data['options'] = $options; return $this->rawStart($data); } @@ -248,6 +252,7 @@ public function startFromURL($url, $output_format) * @param string $content converting file's content. * @param string $input_format input format. You can view available formats on https://convertio.co/formats/ * @param string $output_format output format. You can view available formats on https://convertio.co/formats/ + * @param array $options conversion options. You can view available options on https://convertio.co/api/docs/ * @return \Convertio\Convertio * * @throws \Exception @@ -255,13 +260,14 @@ public function startFromURL($url, $output_format) * @throws \Convertio\Exceptions\CURLException if there is a general HTTP / network error * */ - public function startFromContent($content, $input_format, $output_format) + public function startFromContent($content, $input_format, $output_format, $options = array()) { $data = array(); $data['input'] = 'base64'; $data['file'] = base64_encode($content); $data['filename'] = 'raw.' . $input_format; $data['outputformat'] = $output_format; + $data['options'] = $options; return $this->rawStart($data); }