When the File constructor throws an exception either from within the constructor itself or from e.g. reader.ReadInfo(), then it is not disposed and leaves the IO.Stream open. This causes problems when using the same file in application code because the o/s thinks the file is still open.
The code needs a try/catch, something like this:
reader = new Reader(stream, this);
Reader.FileInfo info = reader.ReadInfo();
version = info.Version;
trailer = info.Trailer;
if (trailer.ContainsKey(PdfName.Encrypt)) // Encrypted file.
throw new NotImplementedException("Encrypted files are currently not supported.");
indirectObjects = new IndirectObjects(this, info.XrefEntries);
document = new Document(trailer[PdfName.Root]);
document.Configuration.XrefMode = (PdfName.XRef.Equals(trailer[PdfName.Type])
catch (Exception ex)
Log in to post a comment.