From 635693f032395e908978db415fe134845fcf8df7 Mon Sep 17 00:00:00 2001 From: BobLd Date: Sun, 9 Feb 2020 15:23:55 +0000 Subject: [PATCH] Fix #133 Marked content extraction issue --- src/UglyToad.PdfPig/Content/MarkedContentElement.cs | 2 +- src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs | 3 ++- src/UglyToad.PdfPig/Graphics/MarkedContentStack.cs | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/UglyToad.PdfPig/Content/MarkedContentElement.cs b/src/UglyToad.PdfPig/Content/MarkedContentElement.cs index e42a18e0..6c3a1dea 100644 --- a/src/UglyToad.PdfPig/Content/MarkedContentElement.cs +++ b/src/UglyToad.PdfPig/Content/MarkedContentElement.cs @@ -109,7 +109,7 @@ /// public override string ToString() { - return $"Index={Index}, MCID={MarkedContentIdentifier}, Tag={Tag}, Properties={Properties}, Contents={Children.Count}"; + return $"Id={Index}, MCID={MarkedContentIdentifier}, Tag={Tag}, Properties={Properties}, Children={Children.Count}"; } } } diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index fbd0d00d..a3dc979a 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -552,7 +552,8 @@ { if (markedContentStack.CanPop) { - markedContents.Add(markedContentStack.Pop(pdfScanner)); + var mc = markedContentStack.Pop(pdfScanner); + if (mc != null) markedContents.Add(mc); } } diff --git a/src/UglyToad.PdfPig/Graphics/MarkedContentStack.cs b/src/UglyToad.PdfPig/Graphics/MarkedContentStack.cs index f92f845a..c701fd66 100644 --- a/src/UglyToad.PdfPig/Graphics/MarkedContentStack.cs +++ b/src/UglyToad.PdfPig/Graphics/MarkedContentStack.cs @@ -16,14 +16,14 @@ { private readonly Stack builderStack = new Stack(); - private int number; + private int number = -1; private MarkedContentElementActiveBuilder top; public bool CanPop => top != null; public void Push(NameToken name, DictionaryToken properties) { - if (builderStack.Count > 0) + if (builderStack.Count == 0) // only increase index if root { number++; } @@ -42,6 +42,7 @@ { top = builderStack.Peek(); top.Children.Add(result); + return null; // do not return child } else {