Link Search Menu Expand Document

PDF to JPG

Description: PDF to JPEG conversion. High quality rendering. Also works great for thumbnails generation and previews. GET or POST request.

Status Errors

CodeDescription
200The request has succeeded
400bad input parameters
401unauthorized
403not enough credits
405Timeout error. To process large documents or files please use asynchronous mode ( set async parameter to true) and then check the status using /job/check endpoint. If file contains many pages then specify a page range using pages parameter. The number of pages of the document can be obtained using the endpoint /pdf/info

Example

Sample Request:

! Don’t forget to set x-api-key url param or http header param (preferred) to API key, get yours here

POST

{
	"pages" : "",
	"password" : "",
	"url" : "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf"
}

Available methods

[POST] /pdf/convert/to/jpg

  • url required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • pages optional. Comma-separated list of page indices (or ranges) to process. IMPORTANT: the very first page starts at 0 (zero). To set a range use the dash -, for example: 0,2-5,7-. To set a range from index to the last page use range like this: 2- (from page #3 as the index starts at zero and till the of the document). For ALL pages just leave this param empty. Example: 0,2-5,7- means first page, then 3rd page to 6th page, and then the range from 8th (index = 7) page till the end of the document. Must be a String.
  • rect optional. Defines coordinates for extraction, e.g. 51.8, 114.8, 235.5, 204.0. You can use PDF.co PDF Viewer with coordinates to easily select and copy coordinates. Must be a String.

  • encrypt optional. Enable encryption for output file. Must be one of: true, false.
  • async optional. Runs processing asynchronously. Returns Use JobId that you may use with /job/check to check state of the processing (possible states: working, failed, aborted and success). Must be one of: true, false.
  • name optional. File name for generated output. Must be a String.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples. For example, to turn on / off layers for rendering:
    {
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf",
    "pages": "0",
    "profiles": "{\"profiles\": [{\"profile1\": {\"RenderTextObjects\": false,\"RenderVectorObjects\": true,\"RenderImageObjects\": true}} ]}"
    }
    

Description

  • Method: POST
  • URL: /v1/pdf/convert/to/jpg

Query parameters

No query parameters accepted.

Body payload

{
  "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf",
  "pages": "0-"
}

Example responses

/pdf/convert/to/jpg
{
    "urls": [
        "https://pdf-temp-files.s3.amazonaws.com/163425dc6d0244c4a281d3e1a244c68a/sample.jpg"
    ],
    "pageCount": 1,
    "error": false,
    "status": 200,
    "name": "sample.jpg",
    "remainingCredits": 60728
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/to/jpg' \
--header 'x-api-key: ' \
--header 'Content-Type: application/json' \
--data-raw '{
  "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf",
  "pages": "0-"
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("x-api-key", "");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf",
 "pages": "0-"
});

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/pdf/convert/to/jpg", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/pdf/convert/to/jpg',
	'headers': {
		'x-api-key': '',
		'Content-Type': 'application/json'
	},
	body: JSON.stringify({
	 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf",
	 "pages": "0-"
	})

};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/pdf/convert/to/jpg',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS =>'{
  "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf",
  "pages": "0-"
}',
	CURLOPT_HTTPHEADER => array(
		'x-api-key: ',
		'Content-Type: application/json'
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("application/json");
		RequestBody body = RequestBody.create(mediaType, "{\n  \"url\": \"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf\",\n  \"pages\": \"0-\"\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/pdf/convert/to/jpg")
			.method("POST", body)
			.addHeader("x-api-key", "")
			.addHeader("Content-Type", "application/json")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/pdf/convert/to/jpg");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("x-api-key", "");
			request.AddHeader("Content-Type", "application/json");
			var body = @"{" + "\n" +
			@"  ""url"": ""https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf""," + "\n" +
			@"  ""pages"": ""0-""" + "\n" +
			@"}";
			request.AddParameter("application/json", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/pdf/convert/to/jpg"

payload = json.dumps({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf",
 "pages": "0-"
})
headers = {
	'x-api-key': '',
	'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-api-key", "")
$headers.Add("Content-Type", "application/json")

$body = "{`n  `"url`": `"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf`",`n  `"pages`": `"0-`"`n}"

$response = Invoke-RestMethod 'https://api.pdf.co/v1/pdf/convert/to/jpg' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json