PdfDocument holding in-memory lock

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v8)  /  PdfDocument holding in-memory lock

DynamicPDF CoreSuite for .NET (v8) Forum

 Jun 06 2017 3:30 PM
using ceTe.DynamicPDF.Merger;

The line below is holding an in-memory lock
PdfDocument pdfdoc = new PdfDocument(fileName);

This line below does not hold an in-memory lock
PdfDocument pdfdoc = new PdfDocument(File.ReadAllBytes(fileName));

File.ReadAllBytes is properly reading all bytes and Closing the file. PdfDocument needs to be IDisposible or at least have a Close() method.
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.

All times are US Eastern Standard time. The time now is 11:34 AM.