protected internal virtual void ReadPdf() {
try {
fileLength = tokens.File.Length;
pdfVersion = tokens.CheckPdfHeader();
try {
ReadXref();
}
catch (Exception e) {
try {
rebuilt = true;
RebuildXref();
lastXref = -1;
}
catch (Exception ne) {
throw new InvalidPdfException("Rebuild failed: " + ne.Message + "; Original message: " + e.Message);
}
}
try {
ReadDocObj();
}
catch (Exception ne) {
if (ne is BadPasswordException)
throw new BadPasswordException(ne.Message);
if (rebuilt || encryptionError)
throw new InvalidPdfException(ne.Message);
rebuilt = true;
encrypted = false;
RebuildXref();
lastXref = -1;
ReadDocObj();
}
strings.Clear();
ReadPages();
EliminateSharedStreams();
RemoveUnusedObjects();
}
finally {
try {
tokens.Close();
}
catch {
// empty on purpose
}
}
}