Blog

Back to blog posts

Extract pages out of a PDF with REST API

Published Mar 12, 2022

Introduction

We are proud to announce a new feature with for our PdfSharp endpoints: Extract Pages. With this endpoint, you will be able to specify (optionally), a start and end of a page range of your PDF file and API2PDF will extract a new PDF with just that page range only.

Extract pages out of a PDF

You can view the endpoint documentation on our swagger page here: https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/2.0.0#/PdfSharp/pdfSharpExtractPages

In summary, you would make a POST call to this endpoint: https://v2.api2pdf.com/pdfsharp/extract-pages

Specify your authorization header:
Authorization: YOUR-API-KEY

And a JSON payload
{ "url": "https://url-to-your-pdf", "start": 0, "end": 0 }

By default, start and end are 0. With both as 0, it will take all pages as the PDF. The ranges are 0-indexed and end is exclusive. Now for examples:

Get all pages except the first page of the PDF
{ "url": "https://url-to-your-pdf", "start": 1 }

Get all pages except the last page

{ "url": "https://url-to-your-pdf", "end": -1 }

Get only the first page of the PDF

{ "url": "https://url-to-your-pdf", "end": 1 }

Get only the last page of the PDF

{ "url": "https://url-to-your-pdf", "start": -1 }

Get pages 2 through 5 of the PDF

{ "url": "https://url-to-your-pdf", "start": 1, "end": 6 }

Get pages 2 and leave off the last 3 pages of the PDF

{ "url": "https://url-to-your-pdf", "start": 1, "end": -3 }

Get between the last 4 pages and second to last page of the PDF

{ "url": "https://url-to-your-pdf", "start": -4, "end": -2 }

We will be updating our client libraries to support this new endpoint, but you can get started with it right away if you know how to make REST API calls with your programming language of choice. Get started now by getting your API key at https://portal.api2pdf.com