Skip to main content

Delete Pages From a PDF


Delete pages form a PDF document.

Use the pdf endpoint to extract pages from an existing PDF.

In this example you start with a nine-page document and then delete pages 4-5 and 8-9. To accomplish this page deletion, merge two copies of the same document where the first copy extracts pages 1-3 and the second document extracts pages 6-7. The following example illustrates.

tip

Check out Getting Started and Task Roadmap if you are new to The DynamicPDF API.

Calling Endpoint Directly​

The following JSON instructions document illustrates deleting pages from a PDF. It inputs the same document twice, where the first instance only selects pages 1, 2, and 3, while the second selects pages 6 and 7, effectively deleting pages 4, 5, 9, and 10.

{
"author": "CeteSoftware",
"creator": "DynamicPDF API",
"inputs": [
{
"type": "pdf",
"resourceName": "pdfnumberedinput.pdf",
"startPage": 1,
"pageCount": 3
},
{
"type": "pdf",
"resourceName": "pdfnumberedinput.pdf",
"startPage": 6,
"pageCount": 2
}
]
}

Run In Postman

curl --location 'https://api.dpdf.io/v1.0/pdf'
--header 'Authorization: Bearer DP--api-key--
--form 'Instructions=@C:/temp/solutions/delete-pages/instructions.json'
--form 'Resource=@C:/temp/solutions/delete-pages/pagenumberedinput.pdf'

Calling Endpoint Using Client Library​

The following JSON instructions document illustrates deleting pages from a PDF using the six different client libraries.

static void PerformDelete(string apiKey, string basePath, string outputPath)
{
Pdf pdf = new Pdf();
pdf.Author = "Test Author";
pdf.Creator = "Test Creator";

PdfInput input = pdf.AddPdf(new PdfResource(basePath + "pdfnumberedinput.pdf"));
input.StartPage = 1;
input.PageCount = 3;

PdfInput input2 = pdf.AddPdf(new PdfResource(basePath + "pdfnumberedinput.pdf"));
input2.StartPage = 6;
input2.PageCount = 2;

pdf.ApiKey = apiKey;
PdfResponse response = pdf.Process();

File.WriteAllBytes(outputPath + "/delete-pages-output.pdf", response.Content);
}
Source: DeletePages.cs
info

The pdf endpoint takes a JSON instructions document that provides instructions for creating, transforming, merging, and formatting inputs into a combined PDF. Refer to documentation on the instructions schema for information on how to use the pdf endpoint.

   Follow us on social media for latest news!