Link Search Menu Expand Document

PDF Delete Pages

Delete pages from PDF document.

Available methods

[POST] /pdf/edit/delete-pages

  • 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 remove. IMPORTANT: the very first page starts at 1 (one). To set a range use the dash -, for example: 1,2-5,7-. To set a range from index to the last page use range like this: 2-. For ALL pages just leave this param empty. Must be a String.

  • 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.

Description

  • Method: POST
  • URL: /v1/pdf/edit/delete-pages

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
    "pages": "1-2",
    "name": "result.pdf"
}

Example responses

/pdf/edit/delete-pages
{
    "url": "https://pdf-temp-files.s3.amazonaws.com/d15e5b2c89c04484ae6ac7244ac43ac2/result.pdf",
    "pageCount": 2,
    "error": false,
    "status": 200,
    "name": "result.pdf",
    "remainingCredits": 60100
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/edit/delete-pages' \
--header 'x-api-key: ' \
--data-raw '{
    "url": "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
    "pages": "1-2",
    "name": "result.pdf"
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("x-api-key", "");

var raw = JSON.stringify({
 "url": "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
 "pages": "1-2",
 "name": "result.pdf"
});

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

fetch("https://api.pdf.co/v1/pdf/edit/delete-pages", 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/edit/delete-pages',
	'headers': {
		'x-api-key': ''
	},
	body: JSON.stringify({
	 "url": "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
	 "pages": "1-2",
	 "name": "result.pdf"
	})

};
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/edit/delete-pages',
	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.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
    "pages": "1-2",
    "name": "result.pdf"
}',
	CURLOPT_HTTPHEADER => array(
		'x-api-key: '
	),
));

$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("text/plain");
		RequestBody body = RequestBody.create(mediaType, "{\n    \"url\": \"https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf\",\n    \"pages\": \"1-2\",\n    \"name\": \"result.pdf\"\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/pdf/edit/delete-pages")
			.method("POST", body)
			.addHeader("x-api-key", "")
			.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/edit/delete-pages");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("x-api-key", "");
			var body = @"{" + "\n" +
			@"    ""url"": ""https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf""," + "\n" +
			@"    ""pages"": ""1-2""," + "\n" +
			@"    ""name"": ""result.pdf""" + "\n" +
			@"}";
			request.AddParameter("text/plain", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/pdf/edit/delete-pages"

payload = json.dumps({
 "url": "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf",
 "pages": "1-2",
 "name": "result.pdf"
})
headers = {
	'x-api-key': ''
}

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", "")

$body = "{`n    `"url`": `"https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf`",`n    `"pages`": `"1-2`",`n    `"name`": `"result.pdf`"`n}"

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