diff --git a/src/UglyToad.PdfPig.Tests/Integration/DocumentInformationTests.cs b/src/UglyToad.PdfPig.Tests/Integration/DocumentInformationTests.cs index 84f8e7159..112800427 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/DocumentInformationTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/DocumentInformationTests.cs @@ -82,5 +82,20 @@ public void CanReadInvalidDocumentInformation() var ex = Assert.Throws(() => PdfDocument.Open(path, ParsingOptions.LenientParsingOff)); Assert.Equal("Expected name as dictionary key, instead got: Collaborative", ex.Message); } + + [Fact] + public void CanReadDocumentInformationIndirectRef() + { + // Issue 706 + var path = IntegrationHelpers.GetSpecificTestDocumentPath("EBOOK-DIETETYKA-SPORTOWA_copy_1.pdf"); + + using (var document = PdfDocument.Open(path)) + { + var information = document.Information; + Assert.Equal("EBOOK", information.Title); + Assert.Equal("Pages", information.Creator); + Assert.Equal("D:20190306232856Z00'00'", information.CreationDate); + } + } } } diff --git a/src/UglyToad.PdfPig.Tests/Integration/SpecificTestDocuments/EBOOK-DIETETYKA-SPORTOWA_copy_1.pdf b/src/UglyToad.PdfPig.Tests/Integration/SpecificTestDocuments/EBOOK-DIETETYKA-SPORTOWA_copy_1.pdf new file mode 100644 index 000000000..00ef3e1b4 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Integration/SpecificTestDocuments/EBOOK-DIETETYKA-SPORTOWA_copy_1.pdf differ diff --git a/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs b/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs index dbedf5dc4..c99da2ca6 100644 --- a/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs +++ b/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs @@ -25,14 +25,14 @@ public static DocumentInformation Create(IPdfTokenScanner pdfTokenScanner, Trail var token = DirectObjectFinder.Get(trailer.Info.Value, pdfTokenScanner); if (token is DictionaryToken infoParsed) { - var title = GetEntryOrDefault(infoParsed, NameToken.Title); - var author = GetEntryOrDefault(infoParsed, NameToken.Author); - var subject = GetEntryOrDefault(infoParsed, NameToken.Subject); - var keywords = GetEntryOrDefault(infoParsed, NameToken.Keywords); - var creator = GetEntryOrDefault(infoParsed, NameToken.Creator); - var producer = GetEntryOrDefault(infoParsed, NameToken.Producer); - var creationDate = GetEntryOrDefault(infoParsed, NameToken.CreationDate); - var modifiedDate = GetEntryOrDefault(infoParsed, NameToken.ModDate); + var title = GetEntryOrDefault(infoParsed, NameToken.Title, pdfTokenScanner); + var author = GetEntryOrDefault(infoParsed, NameToken.Author, pdfTokenScanner); + var subject = GetEntryOrDefault(infoParsed, NameToken.Subject, pdfTokenScanner); + var keywords = GetEntryOrDefault(infoParsed, NameToken.Keywords, pdfTokenScanner); + var creator = GetEntryOrDefault(infoParsed, NameToken.Creator, pdfTokenScanner); + var producer = GetEntryOrDefault(infoParsed, NameToken.Producer, pdfTokenScanner); + var creationDate = GetEntryOrDefault(infoParsed, NameToken.CreationDate, pdfTokenScanner); + var modifiedDate = GetEntryOrDefault(infoParsed, NameToken.ModDate, pdfTokenScanner); return new DocumentInformation(infoParsed, title, author, subject, keywords, creator, producer, creationDate, modifiedDate); @@ -63,7 +63,7 @@ public static DocumentInformation Create(IPdfTokenScanner pdfTokenScanner, Trail throw new PdfDocumentFormatException($"Unknown document information token was found {token.GetType().Name}"); } - private static string GetEntryOrDefault(DictionaryToken infoDictionary, NameToken key) + private static string GetEntryOrDefault(DictionaryToken infoDictionary, NameToken key, IPdfTokenScanner pdfTokenScanner) { if (infoDictionary == null) { @@ -75,6 +75,21 @@ private static string GetEntryOrDefault(DictionaryToken infoDictionary, NameToke return null; } + if (value is IndirectReferenceToken idr) + { + if (DirectObjectFinder.TryGet(idr, pdfTokenScanner, out StringToken strI)) + { + return strI.Data; + } + + if (DirectObjectFinder.TryGet(idr, pdfTokenScanner, out HexToken hexI)) + { + return hexI.Data; + } + + return null; + } + if (value is StringToken str) { return str.Data;