Split a Large PDF Before Uploading It to ChatGPT
Split a PDF that hits ChatGPT's 512 MB / 2M-token file limits with pypdf, then use pdftotext to confirm it has a text layer and that no pages were lost.
Cut a 120-page PDF into five 25-page files, then check that the page and word counts survive the split. ChatGPT reads the text layer of an uploaded PDF, so rule out scanned files before you split. To keep several files together for repeated use, see ChatGPT projects, instructions and memory.
[1] Check the limits first. OpenAI's file upload FAQ says a single file can't exceed 512 MB, and text and document files have a separate cap of 2M tokens per file (spreadsheets are exempt from the token cap). A small file with a very long text can still hit it. Limits change, so re-read the help article before uploading.
[2] Install the tools. pdfinfo and pdftotext come from poppler-utils; split with Python's pypdf inside a virtual environment so nothing system-wide changes.
$ python3 -m venv .venv$ .venv/bin/pip install pypdf$ pdfinfo report.pdf | grep PagesPages: 120[3] Check for a text layer. A PDF with text makes pdftotext print words; a scan, with only a picture on each page, prints almost nothing.
$ pdftotext report.pdf - | wc -w53400$ pdftotext scan.pdf - | wc -w0$ pdfimages -list scan.pdf | head -3page num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio-------------------------------------------------------------------------------------------- 1 0 image 1240 1754 rgb 3 8 jpeg no 9 0 150 150 34.5K 0.5%Zero words and only image rows means a scan. Splitting it won't help, because there is no text to read. Run OCR first.
[4] Write the split script. Arguments: the source file and the number of pages per part.
import sysfrom pypdf import PdfReader, PdfWriter src, n = sys.argv[1], int(sys.argv[2])r = PdfReader(src)total = len(r.pages)for k, s in enumerate(range(0, total, n), 1): w = PdfWriter() for i in range(s, min(s + n, total)): w.add_page(r.pages[i]) out = f"part-{k:02d}.pdf" with open(out, "wb") as f: w.write(f) print(out, f"pages {s + 1}-{min(s + n, total)}")[5] Split into 25-page parts. The last file holds the remaining pages.
$ .venv/bin/python split.py report.pdf 25part-01.pdf pages 1-25part-02.pdf pages 26-50part-03.pdf pages 51-75part-04.pdf pages 76-100part-05.pdf pages 101-120[6] Verify the parts against the original. Page totals and word totals must match.
#!/bin/bash# usage: check.sh original.pdf part-*.pdforig=$1; shiftecho "original: $(pdfinfo "$orig" | awk '/Pages/{print $2}') pages, $(pdftotext "$orig" - | wc -w) words"p=0; w=0for f in "$@"; do np=$(pdfinfo "$f" | awk '/Pages/{print $2}'); nw=$(pdftotext "$f" - | wc -w) printf "%s %3d pages %6d words %7d bytes\n" "$f" "$np" "$nw" "$(stat -c %s "$f")" p=$((p+np)); w=$((w+nw))doneecho "parts: $p pages, $w words"$ bash check.sh report.pdf part-*.pdforiginal: 120 pages, 53400 wordspart-01.pdf 25 pages 11125 words 20464 bytespart-02.pdf 25 pages 11125 words 20423 bytespart-03.pdf 25 pages 11125 words 20442 bytespart-04.pdf 25 pages 11125 words 20463 bytespart-05.pdf 20 pages 8900 words 16450 bytesparts: 120 pages, 53400 words[7] Upload part-*.pdf to a ChatGPT conversation. Describe the file layout in your first message so later questions don't go astray.
part-01 to part-05.pdf are one 120-page report split into 25-page pieces, in file-number order.When you answer, cite the file name and page number you relied on.