Posted by a ceTe Software moderator
Hello,
The file locking behavior of PdfDocument object you are seeing is expected. If you read in the PDF file directly using file path, that file is locked and that lock is automatically set for destruction (or disposed) only after the Draw method is called. The reason for the lock is that the API may need to access the input PDF multiple times as the final PDF is being generated. However, once the final PDF is generated and saved (after Draw method execution) the lock on the input PDF is disposed automatically.
File.ReadAllBytes functions differently, once it reads the PDF to a byte array its job is done, so it is disposing the file lock immediately. Due to the reason describe above the PdfDocument object cannot function similar to File.ReadAllBytes and dispose the file lock as soon as the PdfDocument object is created.
If you don’t want the input PDF file getting locked after PdfDocument object is created, you have to read in the PDF using File.ReadAllBytes method and create the PdfDocument object from that byte array.
Thanks,
ceTe Software Support Team.