Integration-PDF API – Fast and Affordable Document Generation-extract-pages-from-pdf

Extract Pages from PDF

Extract specific pages from a PDF by providing a page number or a range like 3 or 2-4. Ideal for splitting documents or isolating sections.


CustomJS Code

const { EXTRACT_PAGES_FROM_PDF } = require('./utils'); 

const pdfInput = input.file || input.url;

return EXTRACT_PAGES_FROM_PDF(pdfInput, input.pageRange);

Reponse Type

Make sure that the response type is set to PDF.

Execution via API request

Option 1: Passing the PDF as a URL

Here you can see how to extract the first page out of your PDF using a passed URL:

curl -X POST https://e.customjs.io/zeXXXy \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY_HERE" \
  -d '{
    "url": "https://css4.pub/2017/newsletter/drylab.pdf",
    "pageRange": "1"
  }' --output first-page.pdf

Option 2: Passing the PDF as a base64 encoded string

This shows how to extract some pages out of your PDF by sending a binary Base64-encoded string. Keep in mind that the payload size is limited to 6 MB.

curl -X POST https://e.customjs.io/zeXXXy \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY_HERE" \
  -d '{
    "file": "JVBERi0x..........EyNzg3CiUlRU9GCg==",
    "pageRange": "1-2"
  }' --output test-by-string.pdf