Extended the check if PDF is empty before closing the document.

resolves #346