Many fixes to PDF handling but a few layout calculations still needed