From 9afceed1c5d2bdb08117a777ffd38903fb972734 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sat, 11 May 2019 10:49:04 +0100 Subject: [PATCH] correctly delimit content streams when concatenating arrays --- src/UglyToad.PdfPig/Parser/PageFactory.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/UglyToad.PdfPig/Parser/PageFactory.cs b/src/UglyToad.PdfPig/Parser/PageFactory.cs index 7bebcc75..af6a99a2 100644 --- a/src/UglyToad.PdfPig/Parser/PageFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PageFactory.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using Annotations; using Content; - using Encryption; using Exceptions; using Filters; using Geometry; @@ -70,24 +69,31 @@ else if (DirectObjectFinder.TryGet(contents, pdfScanner, out var array)) { var bytes = new List(); - - foreach (var item in array.Data) + + for (var i = 0; i < array.Data.Count; i++) { + var item = array.Data[i]; + if (!(item is IndirectReferenceToken obj)) { throw new PdfDocumentFormatException($"The contents contained something which was not an indirect reference: {item}."); } var contentStream = DirectObjectFinder.Get(obj, pdfScanner); - + if (contentStream == null) { throw new InvalidOperationException($"Could not find the contents for object {obj}."); } bytes.AddRange(contentStream.Decode(filterProvider)); - } + if (i < array.Data.Count - 1) + { + bytes.Add((byte)'\n'); + } + } + content = GetContent(bytes, cropBox, userSpaceUnit, isLenientParsing); } else