private static PdfDocument OpenDocument(IInputBytes inputBytes, ISeekableTokenScanner scanner, IContainer container, bool isLenientParsing) { var log = container.Get <ILog>(); var filterProvider = container.Get <IFilterProvider>(); var catalogFactory = new CatalogFactory(); var cMapCache = new CMapCache(new CMapParser()); CrossReferenceTable crossReferenceTable = null; var bruteForceSearcher = new BruteForceSearcher(inputBytes); var xrefValidator = new XrefOffsetValidator(log); var objectChecker = new XrefCosOffsetChecker(log, bruteForceSearcher); // We're ok with this since our intent is to lazily load the cross reference table. // ReSharper disable once AccessToModifiedClosure var locationProvider = new ObjectLocationProvider(() => crossReferenceTable, bruteForceSearcher); var pdfScanner = new PdfTokenScanner(inputBytes, locationProvider, filterProvider); var crossReferenceStreamParser = new CrossReferenceStreamParser(filterProvider); var crossReferenceParser = new CrossReferenceParser(log, xrefValidator, objectChecker, crossReferenceStreamParser, new CrossReferenceTableParser()); var version = container.Get <FileHeaderParser>().Parse(scanner, isLenientParsing); var crossReferenceOffset = container.Get <FileTrailerParser>().GetFirstCrossReferenceOffset(inputBytes, scanner, isLenientParsing); // TODO: make this use the scanner. var validator = new CrossReferenceOffsetValidator(xrefValidator); crossReferenceOffset = validator.Validate(crossReferenceOffset, scanner, inputBytes, isLenientParsing); crossReferenceTable = crossReferenceParser.Parse(inputBytes, isLenientParsing, crossReferenceOffset, pdfScanner, scanner); var trueTypeFontParser = new TrueTypeFontParser(); var fontDescriptorFactory = new FontDescriptorFactory(); var cidFontFactory = new CidFontFactory(pdfScanner, fontDescriptorFactory, trueTypeFontParser, filterProvider); var encodingReader = new EncodingReader(pdfScanner); var compactFontFormatIndexReader = new CompactFontFormatIndexReader(); var fontFactory = new FontFactory(log, new Type0FontHandler(cidFontFactory, cMapCache, filterProvider, pdfScanner), new TrueTypeFontHandler(log, pdfScanner, filterProvider, cMapCache, fontDescriptorFactory, trueTypeFontParser, encodingReader), new Type1FontHandler(pdfScanner, cMapCache, filterProvider, fontDescriptorFactory, encodingReader, new Type1FontParser(new Type1EncryptedPortionParser()), new CompactFontFormatParser(new CompactFontFormatIndividualFontParser(compactFontFormatIndexReader, new CompactFontFormatTopLevelDictionaryReader(), new CompactFontFormatPrivateDictionaryReader()), compactFontFormatIndexReader)), new Type3FontHandler(pdfScanner, cMapCache, filterProvider, encodingReader)); var resourceContainer = new ResourceContainer(pdfScanner, fontFactory); var pageFactory = new PageFactory(pdfScanner, resourceContainer, filterProvider, new PageContentParser(new ReflectionGraphicsStateOperationFactory()), new XObjectFactory()); var informationFactory = new DocumentInformationFactory(); var rootDictionary = ParseTrailer(crossReferenceTable, isLenientParsing, pdfScanner); var information = informationFactory.Create(pdfScanner, crossReferenceTable.Trailer); var catalog = catalogFactory.Create(pdfScanner, rootDictionary); var caching = new ParsingCachingProviders(bruteForceSearcher, resourceContainer); return(new PdfDocument(log, inputBytes, version, crossReferenceTable, isLenientParsing, caching, pageFactory, catalog, information, pdfScanner)); }