mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-25 10:39:01 -06:00
A page's /Contents array is one content stream in pieces, and a writer may split it between any two tokens (ISO 32000-2 §7.8.2): a TJ array can end one piece with its operator starting the next, and a marked-content dictionary can close at the start of the next piece. Replacing a line or rewriting a paragraph re-serialized the parsed operators of the line's piece, and the parser keeps neither operands left at the end of a piece nor a dictionary's closing >> at its start. The edit dropped them: the text after the edited line vanished, and the page was left with an operator without operands (TJ, BDC), which other readers reject. The piece is now rewritten by splicing: only the replaced, inserted and removed operators change, and every other byte is copied as it was. Co-authored-by: EthanSuquet <292885762+EthanSuquet@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Brandon Thomas <echelon@gmail.com>