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.
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.
Log in to your account to establish a session before calling these endpoints. Requests from an unauthenticated client receive a 401 response.
Endpoints
POST /api-hub/page-extractor/analyzePOST /api-hub/page-extractor/extractGET /api-hub/page-extractor/download/<filename>Analyze File
Upload a PDF file to inspect its page count, file type, and size before extraction. Upload the file as multipart/form-data.
Form Parameters
| Field | Type | Description |
|---|---|---|
file | File | PDF 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
Extract selected pages from a previously analyzed PDF. Send a JSON body referencing the analyzed filename.
JSON Parameters
| Field | Type | Default | Description |
|---|---|---|---|
filename | string | โ | Name of the analyzed file (required) |
pages | string | all | Pages to extract โ all, single page, range, or comma list |
format | string | original | Output format โ original, jpg, png, pdf, pdf_combined |
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
Download an extracted result file. Use the filenames returned by the /extract endpoint.
Path Parameter
| Parameter | Type | Description |
|---|---|---|
filename | string | The result filename returned by /extract (required) |
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:
| Format | Example | Description |
|---|---|---|
all | all | Extract every page (default) |
| Single page | 1 | Extract only the first page |
| Range | 1-3 | Extract pages 1 through 3 inclusive |
| Comma list | 1,3,5 | Extract specific individual pages |
| Mixed | 1-5, 7, 9-11 | Combine ranges and individual pages |
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 download400No file uploaded / not a PDF / missing filename / invalid page range401Not authenticated / session required404File not found โ analyze the file again before extracting429Rate limit / daily usage exceeded500PDF library unavailable / job failed / timed out