pdftoimghttps://api.pixlab.io/pdftoimg
Description
Convert a PDF document to a high resolution JPEG/PNG image format. A single page is converted at once for efficiency & better image resolution. This endpoint is available starting from the Prod Plan and up.
HTTP Methods
GET, POST
Request Parameters
Required
Fields | Type | Description |
---|---|---|
src | URL | Input PDF URL. If you want to upload your PDF directly from your app, then submit a multipart/form-data POST request. |
key | String | Your PixLab API Key. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to. |
Optional
Fields | Type | Description |
---|---|---|
pagenumber | Integer | Target page number to convert. If this field is missing, then the first PDF page (index 0) is extracted. Also if the given page number is out of range, then the last page is extracted & converted. |
export | String | Output image format such as JPEG or PNG. |
blob | Boolean | By default, this command return a JSON object holding the link to the image output. But, if this parameter is set to true then the image binary contents is returned instead. |
POST Request Body (If you plan to use POST instead of a simple GET request)
Allowed Content-Type:
multipart/form-data
application/json
Use multipart/form-data if you want to upload your PDF directly (Refer to the sample set for a working example). If you are using JSON, then your PDF must be already uploaded somewhere.
Response
application/json if the optional blob parameter is not set.
This command return a JSON object after each call only if the optional blob parameter is not set. Otherwise the converted image is returned instead. The following are the JSON fields returned in response body:
Fields | Type | Description |
---|---|---|
status | Integer | Status code 200 indicates success. Any other code indicates failure. |
link | URL | Link to the image output which is usually stored on the highly efficient pixlab.xyz storage server unless you set your own S3 keys (Refer to your dashboard on how to do that). |
id | String | Unique media ID. |
error | String | Error message if status != 200. |
Python Example
import requests
import json
# Convert a PDF document to JPEG/PNG image via /pdftoimg.
req = requests.get('https://api.pixlab.io/pdftoimg',params={
'src':'https://www.getharvest.com/downloads/Invoice_Template.pdf',
'export': 'jpeg',
'key':'My_PixLab_Key'
})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
else:
print ("Link to the image output (Converted PDF page): "+ reply['link'])