# Fix pypdf "PdfReadError: EOF marker not found" on a concatenated contract portfolio

## TL;DR
The portfolio was built by appending PDF bytes together instead of merging, leaving multiple end-of-file markers and one broken cross-reference table. Merge the portfolio properly with a PDF library's append (one trailer, one xref), or repair the bundle with qpdf, then re-run your extraction.

```text
PdfReadError: EOF marker not found
```

## Steps
1. Confirm the cause: check whether the file contains multiple end-of-file markers.
   Expected: more than one marker, confirming a byte-appended bundle rather than a merged PDF.
2. If you have the source files, merge them properly: append each file with pypdf's PdfWriter and write the result once.
   Expected: a single trailer and xref; the portfolio opens cleanly.
3. If you only have the bundle, try repairing it with qpdf, which rebuilds a single xref over the concatenated objects.
   Expected: qpdf exits 0 and the repaired file opens in pypdf.
4. Re-run your extraction on the repaired file and verify the page count covers every member document.
   Expected: all pages present, in order, no missing sections.

## Use this when
- pypdf raises "PdfReadError: EOF marker not found" on a multi-document bundle
- Someone built the portfolio by appending bytes instead of using a merge tool
- A concatenated file opens partially in viewers but fails in parsers

## Not for this skill when
- A single normal PDF raises this (that's corruption or truncation, not concatenation)
- The file is password-protected (decrypt first)
- You need to split the bundle apart (that's a different operation; repair first, then split)

## Variant phrasings
### pypdf eof marker not found merged pdf
"Merge" via byte-append isn't a merge; rebuild with PdfWriter.
### concatenate pdfs python pypdf error
Use PdfWriter append per file and a single write; never concatenate bytes.
### repair concatenated pdf multiple eof markers
qpdf can rebuild one xref over the bundle when the sources are gone.

## Why it happens
PDF is not a concatenable format: each file ends with its own trailer and cross-reference table pointing at its own byte offsets. Appending bytes stacks multiple trailers and invalidates every offset, so the parser can't find a valid end-of-file structure. Viewers sometimes limp through by reading the first document; strict parsers fail.

## Edge cases
- Mixed page sizes and orientations survive a proper merge fine; that's not the issue.
- Encrypted member files must be decrypted before merging; one locked file poisons the bundle.
- After repair, verify page order and count; byte-appended bundles can interleave oddly if a member was linearized.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_lvqNDbHT_Y5hgjZW2vpasQ
