PDFBOX-2576: merge identical code from two branches

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1647195 13f79535-47bb-0310-9956-ffa450edef68