Skip to content

Commit

Permalink
Added an ability to perform OCR via API
Browse files Browse the repository at this point in the history
  • Loading branch information
Dantist committed Jun 11, 2017
1 parent 6a432d1 commit aabb353
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<a href="https://convertio.co/api/docs/#ocr_langs">Full list of available languages</a>):
```php
<?php
require_once 'autoload.php'; // Comment this line if you use Composer to install the package

use \Convertio\Convertio;

$API = new Convertio("_YOUR_API_KEY_");
$API->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**
Expand Down
12 changes: 9 additions & 3 deletions src/Convertio.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,20 @@ 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
* @throws \Convertio\Exceptions\APIException if the Convertio API returns an error
* @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);

Expand All @@ -223,19 +225,21 @@ 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
* @throws \Convertio\Exceptions\APIException if the Convertio API returns an error
* @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);
}
Expand All @@ -248,20 +252,22 @@ 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
* @throws \Convertio\Exceptions\APIException if the Convertio API returns an error
* @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);
}
Expand Down

0 comments on commit aabb353

Please sign in to comment.