Quick start
Give it a PDF that bundles several documents, such as a scanned stack or a tax return with its schedules, and get back each document's pages and its type, among the types you name.
1. Set up
Create an API key in the PageIndex Console and set it:
export PAGEINDEX_API_KEY="your-pageindex-key"
Install the SDK:
pip install -U pageindex
2. Split a PDF
Name each type, with a description where the name alone may not be enough, then call split(). It uploads the PDF, splits it and waits for the result.
from pageindex import PageSplitClient
client = PageSplitClient() # reads PAGEINDEX_API_KEY
types = {
"Form 1040": "An individual income tax return",
"Schedule K-1": "A partner's share of a partnership's income",
"W-2": "An employer's statement of wages and tax withheld",
}
job = client.split("returns.pdf", types)
for doc in job["documents"]:
print(doc["start_page"], doc["end_page"], doc["type"])
1 3 Form 1040
4 5 Schedule K-1
6 7 Schedule K-1
8 8 None
Every page is in one document, in page order. A document that is none of your types, such as a cover letter, comes back with type None. Types are optional: without them the PDF is still split, and every type is None.
The PDF is kept in your "Page Split" collection (collection names another). To split a document you already uploaded, pass its ID in place of the file.
3. Tell documents of one type apart
To label documents of one type by whom or what they are for, such as each partner's K-1, give the type an identifier_key: what tells two of them apart. Two documents of that type with different identifiers are split, and each carries its identifier.
types = [
{"name": "Form 1040", "description": "An individual income tax return"},
{"name": "Schedule K-1", "description": "A partner's share of a partnership's income",
"identifier_key": "the partner the K-1 is for"},
]
job = client.split("returns.pdf", types)
for doc in job["documents"]:
print(doc["start_page"], doc["end_page"], doc["type"], doc.get("identifier"))
1 3 Form 1040 None
4 5 Schedule K-1 ABC Partners LP
6 7 Schedule K-1 Main Street Fund
8 8 None None
A document has an identifier only when one is read, so use doc.get("identifier").
4. Add your own rules
rules says, in your words, how you want the PDF split:
job = client.split("returns.pdf", types, rules="Keep each state return with its schedules.")
You can name up to 100 types. The types and the rules hold at most 50,000 characters, all told.
Price
Splitting costs $0.005 a page ($5 per 1,000 pages), for every page of the PDF, and you only pay when the job completes. Uploading the PDF with it is free.
Jobs
split() waits for the job, up to an hour by default (timeout). A long PDF takes a while: a few minutes for a few hundred pages, and about ten minutes for 1,000. With wait=False it returns the job pending, and wait_split() or get_split() reads it later by its ID. A job that fails isn't charged; a PDF sent with it is left as a failed document, so send the file again to retry.
Next
- Extract data from each document's pages: the PDF is kept, so it isn't uploaded again.
- Collections with metadata: where your uploaded PDFs are kept.
- API reference: run the same jobs over HTTP.