You really don't want to be doing this from sed. Some PDFs may look like line-oriented text files, but they most assuredly are not.
Since you're already using Python, you can use a Python library for this task.
pdfrw will do this fine for you from pure Python. It will slurp in a PDF file, and rebuild it with whatever changes you want and set file offsets correctly. The following snippet of code should set /PageMode to /UseThumbs in the /Root dictionary of the PDF:
from pdfrw import PdfReader, PdfWriter, PdfName trailer = PdfReader('myfile.pdf') trailer.Root.PageMode = PdfName.UseThumbs PdfWriter().write('mynewfile.pdf', trailer)
Disclaimer: I am the pdfrw author.