Image/File · Standard API · eKYC Core
Convert PDF to images
Converts the requested pages of an uploaded PDF into images and returns one image id per page.
Request
| Name | Type | Required | Description |
|---|---|---|---|
file | file | Required | the PDF file to be uploaded |
pages | array of json object | Required | list of pages to convert to images with their labels and metadata |
metadata | dictionary | Optional | key-value, key should be string, value should be string |
Where each object in pages has following json format:
{
"index": int, // index of the page, starts from 1
"label": string, // label of the page image
"metadata": {...}, // optional, any key-value metadata to store with the page image
}
Sample request
curl -X POST \
https://tv-staging.trustingsocial.com/api/v1/convert_pdf_sync \
-H 'Authorization: TV <YOUR ACCESS KEY>:<CREATED SIGNATURE>' \
-H 'X-TV-Timestamp: 2019-04-21T18:00:15+07:00' \
-F 'file=@"portrait.pdf"' \
-F 'pages="[{\"index\":1, \"label\": \"portrait\"}]"'
Response
data.status carries the verdict, and data.images lists one entry per converted page — the image's id, its page number in the PDF and its label.
{
"data": {
"status": string, "success" or "failure"
"images": [ // list of converted images
{
"id": string, // ID of the image
"page" int, // page number (1-indexed) in the PDF file
"label": string, // label of the image
},
],
"request_id": string // return request id to the client and can use request-id to check logs.
}
"errors": [
{
"code": string,
"message": string,
"detail": {
"field": string, // optional, which parameter is invalid
... // any other information that can be useful for client
},
},
... // other errors
]
}
In case the request processing has been finished, the HTTP status code will be 200, and the data.status is either "success" or "failure" depending on whether the request has been successfully processed or not.
Converting the first page of a PDF comes back like this:
{
"data": {
"images": [
{
"id": "081083a6-55e1-4eae-9c54-523edbae4390",
"label": "portrait",
"page": 1
}
],
"request_id": "0866d821-9548-4445-936c-3a593345fe11",
"status": "success"
}
}
Failure codes
If the data.status is "failure", the "errors" field will tell you why it failed.
| Error code | Description |
|---|---|
page_does_not_exist | The page number doesn't exist in the PDF file |
In case of any other errors, the data field will be empty, and the server sends one of following HTTP status code with error code:
| HTTP code | Error code | Description |
|---|---|---|
401 | access_denied_exception | You are not authorized to perform the action. |
413 | file_too_large_exception | The input file size exceeds the allowed limit (15MB). |
415 | invalid_file_format_exception | The provided file format is not supported (PDF). |
400 | invalid_parameter_exception | Input parameter violates a constraint. |
400 | request_time_too_skewed | The X-TV-Timestamp header is expired, need a newer one. |
404 | image_not_found_exception | The image ID is not found in DB. |
408 | request_timeout_exception | Request takes too long to process |
429 | rate_limit_exception | The number of requests exceeded your throughput limit. |
500 | internal_server_error | Some unexpected error occurs while processing the request |
The codes above are the ones documented for this endpoint. Response errors on the Overview lists the codes for the eKYC Core surface as a whole — the two lists do not match on every endpoint.