Still quite ugly since I'm not as familiar with the PDF spec as you are--not sure which sections can have more than one, for example, so I followed your lead. The "hello.py" module duplicates your example file exactly.
[link|http://www.aminus.org/rbre/python/pdf/|http://www.aminus.org/rbre/python/pdf/]
Grab the files __init__.py, tables.py, and hello.py, and put them in a folder named "pdf" in your site-packages directory. Then run hello.py if you like, or just read. :)
A couple new things:
1. You should use direct methods on strings (like 'replace'), not the string module.
2. I learned about zfill today--never used that before. :)
Der Fu