Overview
This article explains how to delete the last page from a PDF when your documents always contain more than one page, but the total number of pages is not fixed.
Since page counts vary between files, you must determine the last page number dynamically before deleting it.
When to Use This
Use this guide when:
Customers want to remove the final page from a PDF
The PDF always has more than one page
The number of pages changes from file to file (not fixed)
Examples of Customer Questions
Here are typical customer queries that should be resolved using this method:
“How can I delete the last page? My PDFs have different numbers of pages.”
“I need to remove the final page but the number of pages changes every time.”
“Some PDFs have 3 pages and others 12. How do I delete only the last one?”
Step 1 — Retrieve the Total Number of Pages
To determine which page is the last, call:
Endpoint:
POST /v1/pdf/info
Documentation:
https://docs.pdf.co/api-reference/pdf-info-reader#post-%2Fv1%2Fpdf%2Finfo
This endpoint returns important metadata, including:
pageCount→ the total number of pages in the file
You will use this number as the page to delete.
Step 2 — Delete the Last Page Dynamically
After retrieving the total page count (for example, N), use:
Endpoint:
POST /v1/pdf/delete-pages
Documentation:
https://docs.pdf.co/api-reference/pdf-delete-pages
Set the pages parameter to the last page number:
Example: If
pageCount = 5, then"pages": "5"
This ensures that only the final page is removed.
Sample Request (Delete Pages)
{
"url": "pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-split/sample.pdf",
"pages": "1-2",
"name": "result.pdf",
"async": false
}Important:
In your dynamic workflow:
First get the total page count using
/v1/pdf/infoThen replace
"1-2"with"N"(whereN= last page number)
Example dynamic usage:
"pages": "N"
Where N is obtained automatically from the info request.
Summary
To delete the last page from a PDF with a variable number of pages:
Call
/v1/pdf/info→ get total page countUse that page number as the
pagesvalue when calling/v1/pdf/delete-pagesThis reliably removes the final page, regardless of file size or page count changes