Fix issue where pdfDocument is null

Happens when no file is loaded
Merge pull request #5127 from Hengjie/fix-pdfdocument-null

Fix issue where pdfDocument is null