public Type1FontHandler(IPdfTokenScanner pdfScanner, IFilterProvider filterProvider, FontDescriptorFactory fontDescriptorFactory, IEncodingReader encodingReader) { this.pdfScanner = pdfScanner; this.filterProvider = filterProvider; this.fontDescriptorFactory = fontDescriptorFactory; this.encodingReader = encodingReader; }
public TrueTypeFontHandler(IPdfObjectParser pdfObjectParser, IFilterProvider filterProvider, CMapCache cMapCache, FontDescriptorFactory fontDescriptorFactory, TrueTypeFontParser trueTypeFontParser) { this.pdfObjectParser = pdfObjectParser; this.filterProvider = filterProvider; this.cMapCache = cMapCache; this.fontDescriptorFactory = fontDescriptorFactory; this.trueTypeFontParser = trueTypeFontParser; }
public static FontDescriptor GetFontDescriptor(IPdfTokenScanner pdfScanner, DictionaryToken dictionary) { if (!dictionary.TryGet(NameToken.FontDescriptor, pdfScanner, out DictionaryToken parsed)) { throw new InvalidFontFormatException($"No font descriptor indirect reference found in the TrueType font: {dictionary}."); } var descriptor = FontDescriptorFactory.Generate(parsed, pdfScanner); return(descriptor); }
public Type1FontHandler(IPdfTokenScanner pdfScanner, CMapCache cMapCache, IFilterProvider filterProvider, FontDescriptorFactory fontDescriptorFactory, IEncodingReader encodingReader, Type1FontParser type1FontParser) { this.pdfScanner = pdfScanner; this.cMapCache = cMapCache; this.filterProvider = filterProvider; this.fontDescriptorFactory = fontDescriptorFactory; this.encodingReader = encodingReader; this.type1FontParser = type1FontParser; }
public TrueTypeFontHandler(ILog log, IPdfTokenScanner pdfScanner, IFilterProvider filterProvider, FontDescriptorFactory fontDescriptorFactory, IEncodingReader encodingReader, ISystemFontFinder systemFontFinder, IFontHandler type1FontHandler) { this.log = log; this.filterProvider = filterProvider; this.fontDescriptorFactory = fontDescriptorFactory; this.encodingReader = encodingReader; this.systemFontFinder = systemFontFinder; this.type1FontHandler = type1FontHandler; this.pdfScanner = pdfScanner; }
public static FontDescriptor GetFontDescriptor(IPdfTokenScanner pdfScanner, FontDescriptorFactory fontDescriptorFactory, DictionaryToken dictionary, bool isLenientParsing) { if (!dictionary.TryGet(NameToken.FontDescriptor, out var obj)) { throw new InvalidFontFormatException($"No font descriptor indirect reference found in the TrueType font: {dictionary}."); } var parsed = DirectObjectFinder.Get <DictionaryToken>(obj, pdfScanner); var descriptor = fontDescriptorFactory.Generate(parsed, pdfScanner, isLenientParsing); return(descriptor); }
public TrueTypeFontHandler(ILog log, IPdfTokenScanner pdfScanner, IFilterProvider filterProvider, CMapCache cMapCache, FontDescriptorFactory fontDescriptorFactory, TrueTypeFontParser trueTypeFontParser, IEncodingReader encodingReader) { this.log = log; this.filterProvider = filterProvider; this.cMapCache = cMapCache; this.fontDescriptorFactory = fontDescriptorFactory; this.trueTypeFontParser = trueTypeFontParser; this.encodingReader = encodingReader; this.pdfScanner = pdfScanner; }
private static PdfDocument OpenDocument(IInputBytes inputBytes, ISeekableTokenScanner scanner, IContainer container, bool isLenientParsing, string password) { 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, NoOpEncryptionHandler.Instance); var crossReferenceStreamParser = new CrossReferenceStreamParser(filterProvider); var crossReferenceParser = new CrossReferenceParser(log, xrefValidator, objectChecker, crossReferenceStreamParser, new CrossReferenceTableParser()); var version = FileHeaderParser.Parse(scanner, isLenientParsing, log); 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 compactFontFormatIndexReader = new CompactFontFormatIndexReader(); var compactFontFormatParser = new CompactFontFormatParser(new CompactFontFormatIndividualFontParser(compactFontFormatIndexReader, new CompactFontFormatTopLevelDictionaryReader(), new CompactFontFormatPrivateDictionaryReader()), compactFontFormatIndexReader); var rootDictionary = ParseTrailer(crossReferenceTable, isLenientParsing, pdfScanner, out var encryptionDictionary); var encryptionHandler = encryptionDictionary != null ? (IEncryptionHandler) new EncryptionHandler(encryptionDictionary, crossReferenceTable.Trailer, password ?? string.Empty) : NoOpEncryptionHandler.Instance; pdfScanner.UpdateEncryptionHandler(encryptionHandler); var cidFontFactory = new CidFontFactory(pdfScanner, fontDescriptorFactory, trueTypeFontParser, compactFontFormatParser, filterProvider); var encodingReader = new EncodingReader(pdfScanner); var fontFactory = new FontFactory(log, new Type0FontHandler(cidFontFactory, cMapCache, filterProvider, pdfScanner), new TrueTypeFontHandler(log, pdfScanner, filterProvider, cMapCache, fontDescriptorFactory, trueTypeFontParser, encodingReader, new SystemFontFinder(new TrueTypeFontParser())), new Type1FontHandler(pdfScanner, cMapCache, filterProvider, fontDescriptorFactory, encodingReader, new Type1FontParser(new Type1EncryptedPortionParser()), compactFontFormatParser), 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(), log); var informationFactory = new DocumentInformationFactory(); var information = informationFactory.Create(pdfScanner, crossReferenceTable.Trailer); var catalog = catalogFactory.Create(pdfScanner, rootDictionary); var caching = new ParsingCachingProviders(bruteForceSearcher, resourceContainer); var acroFormFactory = new AcroFormFactory(pdfScanner, filterProvider); return(new PdfDocument(log, inputBytes, version, crossReferenceTable, isLenientParsing, caching, pageFactory, catalog, information, encryptionDictionary, pdfScanner, filterProvider, acroFormFactory)); }
private static PdfDocument OpenDocument(IInputBytes inputBytes, ISeekableTokenScanner scanner, ILog log, bool isLenientParsing, IReadOnlyList <string> passwords) { var filterProvider = new MemoryFilterProvider(new DecodeParameterResolver(log), new PngPredictor(), log); 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, NoOpEncryptionHandler.Instance); var crossReferenceStreamParser = new CrossReferenceStreamParser(filterProvider); var crossReferenceParser = new CrossReferenceParser(log, xrefValidator, objectChecker, crossReferenceStreamParser, new CrossReferenceTableParser()); var version = FileHeaderParser.Parse(scanner, isLenientParsing, log); var crossReferenceOffset = FileTrailerParser.GetFirstCrossReferenceOffset(inputBytes, scanner, isLenientParsing) + version.OffsetInFile; // TODO: make this use the scanner. var validator = new CrossReferenceOffsetValidator(xrefValidator); crossReferenceOffset = validator.Validate(crossReferenceOffset, scanner, inputBytes, isLenientParsing); crossReferenceTable = crossReferenceParser.Parse(inputBytes, isLenientParsing, crossReferenceOffset, version.OffsetInFile, pdfScanner, scanner); var fontDescriptorFactory = new FontDescriptorFactory(); var(rootReference, rootDictionary) = ParseTrailer(crossReferenceTable, isLenientParsing, pdfScanner, out var encryptionDictionary); var encryptionHandler = encryptionDictionary != null ? (IEncryptionHandler) new EncryptionHandler(encryptionDictionary, crossReferenceTable.Trailer, passwords) : NoOpEncryptionHandler.Instance; pdfScanner.UpdateEncryptionHandler(encryptionHandler); var cidFontFactory = new CidFontFactory(pdfScanner, fontDescriptorFactory, filterProvider); var encodingReader = new EncodingReader(pdfScanner); var type1Handler = new Type1FontHandler(pdfScanner, filterProvider, fontDescriptorFactory, encodingReader); var fontFactory = new FontFactory(log, new Type0FontHandler(cidFontFactory, filterProvider, pdfScanner), new TrueTypeFontHandler(log, pdfScanner, filterProvider, fontDescriptorFactory, encodingReader, new SystemFontFinder(), type1Handler), type1Handler, new Type3FontHandler(pdfScanner, filterProvider, encodingReader)); var resourceContainer = new ResourceStore(pdfScanner, fontFactory); var information = DocumentInformationFactory.Create(pdfScanner, crossReferenceTable.Trailer); var catalog = CatalogFactory.Create(rootReference, rootDictionary, pdfScanner, isLenientParsing); var pageFactory = new PageFactory(pdfScanner, resourceContainer, filterProvider, new PageContentParser(new ReflectionGraphicsStateOperationFactory()), log); var caching = new ParsingCachingProviders(bruteForceSearcher, resourceContainer); var acroFormFactory = new AcroFormFactory(pdfScanner, filterProvider); var bookmarksProvider = new BookmarksProvider(log, pdfScanner, isLenientParsing); return(new PdfDocument(log, inputBytes, version, crossReferenceTable, isLenientParsing, caching, pageFactory, catalog, information, encryptionDictionary, pdfScanner, filterProvider, acroFormFactory, bookmarksProvider)); }
private static PdfDocument OpenDocument(IRandomAccessRead reader, IInputBytes inputBytes, ISeekableTokenScanner scanner, IContainer container, bool isLenientParsing) { var log = container.Get <ILog>(); var version = container.Get <FileHeaderParser>().Parse(scanner, isLenientParsing); var crossReferenceOffset = container.Get <FileTrailerParser>().GetFirstCrossReferenceOffset(inputBytes, scanner, isLenientParsing); var pool = new CosObjectPool(); // TODO: make this use the scanner. var validator = new CrossReferenceOffsetValidator(new XrefOffsetValidator(log, reader, container.Get <CosDictionaryParser>(), container.Get <CosBaseParser>(), pool)); crossReferenceOffset = validator.Validate(crossReferenceOffset, isLenientParsing); var crossReferenceTable = container.Get <CrossReferenceParser>() .Parse(reader, isLenientParsing, crossReferenceOffset, pool); container.Get <CrossReferenceParser>().ParseNew(crossReferenceOffset, scanner, isLenientParsing); var filterProvider = container.Get <IFilterProvider>(); var bruteForceSearcher = new BruteForceSearcher(reader); var pdfObjectParser = new PdfObjectParser(container.Get <ILog>(), container.Get <CosBaseParser>(), container.Get <CosStreamParser>(), crossReferenceTable, bruteForceSearcher, pool, container.Get <ObjectStreamParser>()); var trueTypeFontParser = new TrueTypeFontParser(); var fontDescriptorFactory = new FontDescriptorFactory(); var cidFontFactory = new CidFontFactory(fontDescriptorFactory, trueTypeFontParser, pdfObjectParser, filterProvider); var cMapCache = new CMapCache(new CMapParser()); var fontFactory = new FontFactory(log, new Type0FontHandler(cidFontFactory, cMapCache, filterProvider, pdfObjectParser), new TrueTypeFontHandler(pdfObjectParser, filterProvider, cMapCache, fontDescriptorFactory, trueTypeFontParser)); var dynamicParser = container.Get <DynamicParser>(); var resourceContainer = new ResourceContainer(pdfObjectParser, fontFactory); var pageFactory = new PageFactory(resourceContainer, pdfObjectParser, filterProvider, new PageContentParser(new ReflectionGraphicsStateOperationFactory())); var informationFactory = new DocumentInformationFactory(); var catalogFactory = new CatalogFactory(pdfObjectParser); var root = ParseTrailer(reader, crossReferenceTable, dynamicParser, bruteForceSearcher, pool, isLenientParsing); if (!(root is PdfDictionary rootDictionary)) { throw new InvalidOperationException("Expected root dictionary, but got this: " + root); } // in some pdfs the type value "Catalog" is missing in the root object if (isLenientParsing && !rootDictionary.ContainsKey(CosName.TYPE)) { rootDictionary.Set(CosName.TYPE, CosName.CATALOG); } var information = informationFactory.Create(pdfObjectParser, crossReferenceTable.Dictionary, reader, isLenientParsing); var catalog = catalogFactory.Create(rootDictionary, reader, isLenientParsing); var caching = new ParsingCachingProviders(pool, bruteForceSearcher, resourceContainer); return(new PdfDocument(log, reader, version, crossReferenceTable, isLenientParsing, caching, pageFactory, pdfObjectParser, catalog, information)); }