diff --git a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs index b12edd45..7dcc9b94 100644 --- a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs +++ b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs @@ -2,7 +2,6 @@ { using System; using System.Collections.Generic; - using CrossReference; using Util.JetBrains.Annotations; /// diff --git a/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs b/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs index 13c1b233..adc207fe 100644 --- a/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs +++ b/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs @@ -39,9 +39,9 @@ public IndirectReference? Info { get; } /// - /// A list containing two-byte strings which act as file identifiers. + /// A list containing two-byte string tokens which act as file identifiers. /// - public IReadOnlyList Identifier { get; } + public IReadOnlyList> Identifier { get; } /// /// The document's encryption dictionary. @@ -77,17 +77,17 @@ if (dictionary.TryGet(NameToken.Id, out ArrayToken arr)) { - var ids = new List(arr.Data.Count); + var ids = new List>(arr.Data.Count); foreach (var token in arr.Data) { if (token is StringToken str) { - ids.Add(str.Data); + ids.Add(str); } else if (token is HexToken hex) { - ids.Add(hex.Data); + ids.Add(hex); } } @@ -95,7 +95,7 @@ } else { - Identifier = EmptyArray.Instance; + Identifier = EmptyArray>.Instance; } if (dictionary.TryGet(NameToken.Encrypt, out var encryptionToken)) diff --git a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs index 9c5fddd0..20db5c25 100644 --- a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs +++ b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs @@ -42,9 +42,27 @@ { this.encryptionDictionary = encryptionDictionary; - var documentIdBytes = trailerDictionary.Identifier != null && trailerDictionary.Identifier.Count == 2 ? - OtherEncodings.StringAsLatin1Bytes(trailerDictionary.Identifier[0]) - : EmptyArray.Instance; + byte[] documentIdBytes; + + if (trailerDictionary.Identifier != null && trailerDictionary.Identifier.Count == 2) + { + var token = trailerDictionary.Identifier[0]; + + switch (token) + { + case HexToken hex: + documentIdBytes = hex.Bytes.ToArray(); + break; + default: + documentIdBytes = OtherEncodings.StringAsLatin1Bytes(token.Data); + break; + } + + } + else + { + documentIdBytes = EmptyArray.Instance; + } password = password ?? string.Empty;