Handles more valid PDFs and CPP support

All these fixes are based on real pdf usage.