Printing fails and the existing file is deleted

Applies to: Windows 8Windows 8.1Windows 10


Consider the following scenario:
  • You print out to a file by specifying an existing file to overwrite it.
  • Another application (e.g. Reader app) is opening the file as a memory-mapped file.
In this scenario, printing operation fails with the following error message:
Invalid handle.
Additonally, the specified existing file is deleted.


This problem may occur because of the behavior of StartDocPrinter API where an application calls to print out. The API tries to open the file exclusively first and if it fails then tries to delete it.


Retry to print out when the problem occurs.


To avoid this problem, specify a non-existent new file as an output file when printing.