precise pdf page extraction

Page Extractor
API Documentation

Extract individual pages from PDF files with precision. Analyze documents to discover page counts, then extract selected pages as single-page files or a combined PDF โ€” with custom page ranges and orderings.

Try it now Back to API Hub

Overview

The Page Extractor API works in two stages. First, analyze an uploaded PDF to learn its page count, size, and type. Then, extract the pages you need โ€” all pages, a single page, a range like 1-3, or a list like 1,3,5. Extracted pages are returned as individual PDF files (bundled into a ZIP when multiple) or as one combined PDF, ready for download. Perfect for splitting documents, pulling specific sections, or rearranging PDF content.

Base URL & Authentication

Base URL

Base URL

https://api.chemhub.com

Authentication

All Page Extractor endpoints require an authenticated session. The endpoints are exposed under the /api-hub/page-extractor/ prefix on the application and rely on your logged-in account session cookie.

Session-based access

Log in to your account to establish a session before calling these endpoints. Requests from an unauthenticated client receive a 401 response.

Endpoints

๐Ÿ” Analyze FilePOST /api-hub/page-extractor/analyze
๐Ÿ“„ Extract PagesPOST /api-hub/page-extractor/extract
โฌ‡๏ธ Download ResultGET /api-hub/page-extractor/download/<filename>

Analyze File

POST/api-hub/page-extractor/analyze

Upload a PDF file to inspect its page count, file type, and size before extraction. Upload the file as multipart/form-data.

Form Parameters

FieldTypeDescription
fileFilePDF file (required). Only .pdf files are supported.

Response

Success Response

{
  "success": true,
  "filename": "document.pdf",
  "size_mb": 4.3,
  "file_type": "PDF",
  "analysis": {
    "pages": 12
  }
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api-hub/page-extractor/analyze"

# Use a requests.Session to keep your login cookies
session = requests.Session()

with open("document.pdf", "rb") as f:
    files = {"file": f}
    res = session.post(url, files=files)

print(res.json())

cURL

curl -X POST "https://api.chemhub.com/api-hub/page-extractor/analyze" \
  -b "session=<your_session_cookie>" \
  -F "file=@document.pdf"

JavaScript

const form = new FormData();
form.append('file', fileInput.files[0]);

fetch('https://api.chemhub.com/api-hub/page-extractor/analyze', {
  method: 'POST',
  credentials: 'include',
  body: form
})
.then(res => res.json())
.then(console.log);

Extract Pages

POST/api-hub/page-extractor/extract

Extract selected pages from a previously analyzed PDF. Send a JSON body referencing the analyzed filename.

JSON Parameters

FieldTypeDefaultDescription
filenamestringโ€”Name of the analyzed file (required)
pagesstringallPages to extract โ€” all, single page, range, or comma list
formatstringoriginalOutput format โ€” original, jpg, png, pdf, pdf_combined
Workflow

You must call /analyze first so the file is stored server-side. The filename value returned by /analyze is required by /extract.

Response

Success Response

{
  "success": true,
  "extracted_files": ["extracted_page_0001.pdf", "extracted_page_0002.pdf"],
  "job_id": "3f9a1c2b"
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api-hub/page-extractor/extract"

session = requests.Session()

payload = {
    "filename": "document.pdf",
    "pages": "1-3",
    "format": "pdf"
}

res = session.post(url, json=payload)
print(res.json())

cURL

curl -X POST "https://api.chemhub.com/api-hub/page-extractor/extract" \
  -b "session=<your_session_cookie>" \
  -H "Content-Type: application/json" \
  -d '{"filename":"document.pdf","pages":"1-3","format":"pdf"}'

JavaScript

fetch('https://api.chemhub.com/api-hub/page-extractor/extract', {
  method: 'POST',
  credentials: 'include',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    filename: 'document.pdf',
    pages: '1-3',
    format: 'pdf'
  })
})
.then(res => res.json())
.then(console.log);

Download Result

GET/api-hub/page-extractor/download/<filename>

Download an extracted result file. Use the filenames returned by the /extract endpoint.

Path Parameter

ParameterTypeDescription
filenamestringThe result filename returned by /extract (required)
Response

On success the endpoint returns the extracted file bytes as a download attachment (Content-Disposition: attachment). If the extraction produced multiple files, download the combined ZIP file instead.

cURL Example

cURL

curl -b "session=<your_session_cookie>" \
  "https://api.chemhub.com/api-hub/page-extractor/download/extracted_page_0001.pdf" \
  --output extracted_page_0001.pdf

Page Specifications

The pages parameter accepts several formats:

FormatExampleDescription
allallExtract every page (default)
Single page1Extract only the first page
Range1-3Extract pages 1 through 3 inclusive
Comma list1,3,5Extract specific individual pages
Mixed1-5, 7, 9-11Combine ranges and individual pages
1-based page numbers

Page numbers in the pages parameter are 1-indexed (page 1 is the first page). Values outside the document's page count are rejected with a 400 error.

Python SDK

Complete Python SDK covering the full analyze โ†’ extract โ†’ download workflow.

Complete SDK Class

import requests

BASE_URL = "https://api.chemhub.com"
session = requests.Session()

# --- Analyze a PDF file ---
def analyze_pdf(pdf_path):
    with open(pdf_path, "rb") as f:
        files = {"file": f}
        res = session.post(f"{BASE_URL}/api-hub/page-extractor/analyze", files=files)
    data = res.json()
    if data.get("success"):
        print(f"Analyzed {data['filename']}: {data['analysis']['pages']} pages")
    return data

# --- Extract pages ---
def extract_pages(filename, pages="all", output_format="pdf"):
    payload = {
        "filename": filename,
        "pages": pages,
        "format": output_format
    }
    res = session.post(f"{BASE_URL}/api-hub/page-extractor/extract", json=payload)
    return res.json()

# --- Download a result file ---
def download_result(result_filename, save_path):
    res = session.get(
        f"{BASE_URL}/api-hub/page-extractor/download/{result_filename}"
    )
    if res.status_code == 200:
        with open(save_path, "wb") as f:
            f.write(res.content)
        print(f"Downloaded to: {save_path}")
        return True
    print(f"Download failed: {res.status_code}")
    return False

# --- Full workflow ---
if __name__ == "__main__":
    print("=== PAGE EXTRACTOR API TEST ===")

    analysis = analyze_pdf("document.pdf")
    if not analysis.get("success"):
        raise SystemExit("Analysis failed")

    result = extract_pages(analysis["filename"], pages="1-3", output_format="pdf")
    print(f"Extraction result: {result}")

    for file in result.get("extracted_files", []):
        download_result(file, file)

Errors & Status Codes

Error Response Format

Error Response

{
  "error": "Only PDF files are supported. Please upload a PDF file."
}

Status Codes

200Success โ€” analysis data, extraction result, or file download
400No file uploaded / not a PDF / missing filename / invalid page range
401Not authenticated / session required
404File not found โ€” analyze the file again before extracting
429Rate limit / daily usage exceeded
500PDF library unavailable / job failed / timed out

Limitations

Supported format: PDF only
Maximum file size: 50MB
Page numbers: 1-based, must be within document page count
Processing timeout: Jobs wait up to 30 seconds
Output format: PDF (single pages) or ZIP bundle / combined PDF