diff --git a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf.IO/PdfReader.cs b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf.IO/PdfReader.cs index 45ab116b..32c00785 100644 --- a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf.IO/PdfReader.cs +++ b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf.IO/PdfReader.cs @@ -308,13 +308,17 @@ PdfDocument OpenFromStream(Stream stream, string? password, PdfDocumentOpenMode // Reference.Values available by now: All trailers and cross-reference streams (which are not encrypted by definition). // 2. Read the encryption dictionary, if existing. - if (_document.Trailer!.Elements[PdfTrailer.Keys.Encrypt] is PdfReference xrefEncrypt) + var trailer = _document.Trailer; + while (trailer != null) { - var encrypt = parser.ReadIndirectObject(xrefEncrypt, null, true); - encrypt.Reference = xrefEncrypt; - xrefEncrypt.Value = encrypt; - - _document.SecurityHandler.PrepareForReading(); + if (_document.Trailer!.Elements[PdfTrailer.Keys.Encrypt] is PdfReference xrefEncrypt) + { + var encrypt = parser.ReadIndirectObject(xrefEncrypt, null, true); + encrypt.Reference = xrefEncrypt; + xrefEncrypt.Value = encrypt; + + _document.SecurityHandler.PrepareForReading(); + } } // References available by now: All references to file-level objects. // Reference.Values available by now: All trailers and cross-reference streams and the encryption dictionary.