private static PdfDictionary ParseTrailer(ISeekableTokenScanner scanner, bool isLenientParsing) { if (scanner.CurrentToken is OperatorToken trailerToken && trailerToken.Data == "trailer") { if (!scanner.TryReadToken(out DictionaryToken trailerDictionary)) { throw new PdfDocumentFormatException($"Expected to find a dictionary in the trailer but instead found: {scanner.CurrentToken}."); } return(PdfDictionary.FromDictionaryToken(trailerDictionary)); } if (isLenientParsing) { var foundTrailer = false; while (scanner.MoveNext()) { if (scanner.CurrentToken is OperatorToken op && op.Data == "trailer") { foundTrailer = true; break; } } if (foundTrailer && scanner.TryReadToken(out DictionaryToken trailerDictionary)) { return(PdfDictionary.FromDictionaryToken(trailerDictionary)); } } throw new PdfDocumentFormatException("No trailer dictionary was present."); }