diff --git a/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs b/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs index 6ccc39d2..faf0dd56 100644 --- a/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs @@ -160,12 +160,25 @@ var cidFontFactory = new CidFontFactory(pdfScanner, filterProvider); var encodingReader = new EncodingReader(pdfScanner); + var type0Handler = new Type0FontHandler( + cidFontFactory, + filterProvider, + pdfScanner, + parsingOptions.Logger); + var type1Handler = new Type1FontHandler(pdfScanner, filterProvider, encodingReader); - var fontFactory = new FontFactory(parsingOptions.Logger, new Type0FontHandler(cidFontFactory, - filterProvider, pdfScanner), - new TrueTypeFontHandler(parsingOptions.Logger, pdfScanner, filterProvider, encodingReader, SystemFontFinder.Instance, - type1Handler), + var trueTypeHandler = new TrueTypeFontHandler(parsingOptions.Logger, + pdfScanner, + filterProvider, + encodingReader, + SystemFontFinder.Instance, + type1Handler); + + var fontFactory = new FontFactory( + parsingOptions.Logger, + type0Handler, + trueTypeHandler, type1Handler, new Type3FontHandler(pdfScanner, filterProvider, encodingReader)); diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs index d12e2162..fe29aa79 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs @@ -7,6 +7,7 @@ using Core; using Filters; using Fonts; + using Logging; using Parts; using PdfPig.Parser.Parts; using Tokenization.Scanner; @@ -18,13 +19,18 @@ private readonly CidFontFactory cidFontFactory; private readonly ILookupFilterProvider filterProvider; private readonly IPdfTokenScanner scanner; + private readonly ILog logger; - public Type0FontHandler(CidFontFactory cidFontFactory, ILookupFilterProvider filterProvider, - IPdfTokenScanner scanner) + public Type0FontHandler( + CidFontFactory cidFontFactory, + ILookupFilterProvider filterProvider, + IPdfTokenScanner scanner, + ILog logger) { this.cidFontFactory = cidFontFactory; this.filterProvider = filterProvider; this.scanner = scanner; + this.logger = logger; } public IFont Generate(DictionaryToken dictionary) @@ -79,7 +85,10 @@ } else { - throw new PdfDocumentFormatException($"Invalid type of toUnicode CMap encountered. Got: {toUnicodeValue}."); + // Rather than throwing here, let's try returning the font anyway since + // this error is tripping people up as seen in issues #354 and #619. + // This will probably just cause errors further along the parsing but it might be more informative. + logger.Error($"Invalid type of toUnicode CMap encountered for font named {baseFont}. Got: {toUnicodeValue}."); } }