Convert Image, PDF to Searchable PDF
1. Convert Image, PDF to Searchable PDF with image URL input
API:
| Method | URL | 
|---|---|
| GET | https://demo.computervision.com.vn/api/v2/ocr/document/img_to_pdf | 
Params:
| Key | Value | Description | 
|---|---|---|
img | https://example.com/image.png | URL of photo or pdf | 
format_type | url | Type of data to pass in, receive value: url, file, base64 | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"image_url = 'https://example.com/image.png'response = requests.get("https://demo.computervision.com.vn/api/v2/ocr/document/img_to_pdf?img=%s&format_type=url"% image_url,auth=(api_key, api_secret))print(response.json())
2. Convert Image, PDF to Searchable PDF with image file input
API:
| Method | URL | content-type | 
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/ocr/document/img_to_pdf | multipart/form-data | 
Params:
| Key | Value | Description | 
|---|---|---|
format_type | file | Type of data to pass in, receive value: url, file, base64 | 
Body:
| Key | Type | Value | Description | 
|---|---|---|---|
img | file | example.jpg | Image file or pdf file | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"image_path = '/path/to/your/image.jpg'response = requests.post("https://demo.computervision.com.vn/api/v2/ocr/document/img_to_pdf?format_type=file",auth=(api_key, api_secret),files={'img': open(image_path, 'rb')})print(response.json())
3. Convert Image, PDF to Searchable PDF with JSON input
API:
| Method | URL | content-type | 
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/ocr/document/img_to_pdf | application/json | 
Params:
| Key | Value | Description | 
|---|---|---|
format_type | base64 | Type of data to pass in, receive value: url, file, base64 | 
Body:
{"img": "iVBORw0KGgoAAAANSU..." // string base64 of the image or pdf to extract}
Demo Python:
import base64import ioimport requestsfrom PIL import Imagedef get_byte_img(img):img_byte_arr = io.BytesIO()img.save(img_byte_arr, format='PNG')encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')return encoded_imgapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"img_name = "path_img"encode_cmt = get_byte_img(Image.open(img_name))response = requests.post("https://demo.computervision.com.vn/api/v2/ocr/document/img_to_pdf?format_type=base64",auth=(api_key, api_secret),json={'img' : encode_cmt})print(response.json())
4. Response
The information returned is a Searchable PDF file
Error code table:
| Code | Message | 
|---|---|
| 0 | Success | 
| 1 | Incorrect image format | 
| 2 | Url is unavailable | 
| 3 | The photo does not contain content | 
| 4 | Incorrect api_key or api_secret | 
| 5 | Out of requests | 
| 6 | Error when processing the request |