Test files › Documents › truncated.pdf

Truncated PDF test file

A valid PDF cut off at 60% of its length, simulating an interrupted upload.

↓ Download truncated.pdf
Filenametruncated.pdf
FormatPDF
Size1.4 KB (1,394 bytes)
MIME typeapplication/pdf
SHA-256a0975aad80c61f7b47103d04c4143122aa1a48da51d0c7fe74772f3af3479d7b
What this file catchesUpload handlers that accept a partial file because the magic bytes matched the first 5 bytes. Validate the trailer, not just the header.

Handle it in code

Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.

Python

A cheap structural check before handing the file to a PDF library, which will often repair these silently. Use it to reject or flag uploads, not to validate PDFs fully.

import re

with open("truncated.pdf", "rb") as f:
    data = f.read()

problems = []
if not data.startswith(b"%PDF-"):
    problems.append("no %PDF- header")
tail = data[-1024:]
if b"%%EOF" not in tail:
    problems.append("no %%EOF marker: the file is truncated")
m = re.search(rb"startxref\s+(\d+)\s+%%EOF", tail)
if m:
    offset = int(m.group(1))
    at = data[offset:offset + 20]
    if offset >= len(data) or not (at.startswith(b"xref") or re.match(rb"\d+ \d+ obj", at)):
        problems.append(f"startxref points at byte {offset}, where there is no cross-reference table")

print("; ".join(problems) or "structure looks intact")

Run against this file, it prints: no %%EOF marker: the file is truncated

Related guides and tools

Sample PDF fileFile signaturesPDF extraction traps (RAG)Check a file's real typeVerify its SHA-256

Download & verify

curl -fsSL -o "truncated.pdf" "https://files.hexaqa.com/pdf/truncated.pdf"
curl -fsSL "https://files.hexaqa.com/pdf/truncated.pdf" | sha256sum # expect: a0975aad80c61f7b47103d04c4143122aa1a48da51d0c7fe74772f3af3479d7b

More documents test files

corrupt-xref.pdfempty-zero-pages.pdfno-text-layer.pdfvalid-1page.pdfvalid-500pages.pdflatin1.txtline-endings-crlf.txtline-endings-lf.txt

← All Documents files