Fix #5341 PDF rendering exception in IOS 8 safari

Change was proposed by @spolitakis

Confirmed working on iPhone 5 and iPad 2 with iOS 8