From d3bf63fdbfaa58091fabec02f79fd64eb79f67f8 Mon Sep 17 00:00:00 2001 From: BobLd <38405645+BobLd@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:00:15 +0000 Subject: [PATCH] Move Paths, GetAnnotations() and GetOptionalContents() outside of ExperimentalAccess and mark Experimental class and reference as obsolete --- .../Export/AltoXmlTextExporter.cs | 2 +- .../Export/HOcrTextExporter.cs | 2 +- .../Export/PageXmlTextExporter.cs | 2 +- .../Export/SvgTextExporter.cs | 2 +- .../Geometry/ClippingTests.cs | 2 +- .../Geometry/PdfPathExtensionsTests.cs | 2 +- .../Integration/AnnotationReplyToTests.cs | 6 +- .../Integration/AnnotationsTest.cs | 4 +- .../Integration/CatGeneticsTests.cs | 2 +- .../Integration/ColorSpaceTests.cs | 6 +- .../Integration/IntegrationDocumentTests.cs | 4 +- .../Integration/OptionalContentTests.cs | 10 +- .../Integration/PatternColorTests.cs | 10 +- .../Integration/RotationAndCroppingTests.cs | 2 +- .../GenerateLetterBoundingBoxImages.cs | 2 +- .../Writer/PdfDocumentBuilderTests.cs | 8 +- .../Writer/PdfMergerTests.cs | 4 +- src/UglyToad.PdfPig/Content/Page.cs | 102 +++++++++++------- 18 files changed, 99 insertions(+), 73 deletions(-) diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/AltoXmlTextExporter.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/AltoXmlTextExporter.cs index c259f8338..bfe623cb2 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/AltoXmlTextExporter.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/AltoXmlTextExporter.cs @@ -184,7 +184,7 @@ private AltoDocument.AltoPage ToAltoPage(Page page, bool includePaths) if (includePaths) { - altoPage.PrintSpace.GraphicalElements = page.ExperimentalAccess.Paths + altoPage.PrintSpace.GraphicalElements = page.Paths .Select(p => ToAltoGraphicalElement(p, page.Height)) .ToArray(); } diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/HOcrTextExporter.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/HOcrTextExporter.cs index 7b0fd33f7..edb19ad89 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/HOcrTextExporter.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/HOcrTextExporter.cs @@ -193,7 +193,7 @@ private string GetCode(Page page, bool includePaths, string imageName = "unknown if (includePaths) { - foreach (var path in page.ExperimentalAccess.Paths) + foreach (var path in page.Paths) { hocr += "\n" + GetCode(path, page.Height, true, level + 1); } diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/PageXmlTextExporter.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/PageXmlTextExporter.cs index 47337bba3..324bfa0cd 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/PageXmlTextExporter.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/PageXmlTextExporter.cs @@ -240,7 +240,7 @@ private PageXmlDocument.PageXmlPage ToPageXmlPage(Page page, PageXmlData data, b if (includePaths) { - foreach (var path in page.ExperimentalAccess.Paths) + foreach (var path in page.Paths) { var graphicalElement = ToPageXmlLineDrawingRegion(path, data, page.Width, page.Height); diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/SvgTextExporter.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/SvgTextExporter.cs index 4137ac975..03811df13 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/SvgTextExporter.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export/SvgTextExporter.cs @@ -69,7 +69,7 @@ public string Get(Page page) { var builder = new StringBuilder($"\n\n"); - foreach (var path in page.ExperimentalAccess.Paths) + foreach (var path in page.Paths) { if (!path.IsClipping) { diff --git a/src/UglyToad.PdfPig.Tests/Geometry/ClippingTests.cs b/src/UglyToad.PdfPig.Tests/Geometry/ClippingTests.cs index fa860d16b..d9832e76e 100644 --- a/src/UglyToad.PdfPig.Tests/Geometry/ClippingTests.cs +++ b/src/UglyToad.PdfPig.Tests/Geometry/ClippingTests.cs @@ -11,7 +11,7 @@ public void ContainsRectangleEvenOdd() new ParsingOptions { ClipPaths = true })) { var page = document.GetPage(45); - Assert.Equal(28, page.ExperimentalAccess.Paths.Count); + Assert.Equal(28, page.Paths.Count); } } } diff --git a/src/UglyToad.PdfPig.Tests/Geometry/PdfPathExtensionsTests.cs b/src/UglyToad.PdfPig.Tests/Geometry/PdfPathExtensionsTests.cs index bfbc267f9..dd3b494fb 100644 --- a/src/UglyToad.PdfPig.Tests/Geometry/PdfPathExtensionsTests.cs +++ b/src/UglyToad.PdfPig.Tests/Geometry/PdfPathExtensionsTests.cs @@ -15,7 +15,7 @@ public void ContainsRectangleEvenOdd() var page = document.GetPage(1); var words = page.GetWords().ToList(); - foreach (var path in page.ExperimentalAccess.Paths) + foreach (var path in page.Paths) { Assert.NotEqual(FillingRule.NonZeroWinding, path.FillingRule); // allow none and even-odd diff --git a/src/UglyToad.PdfPig.Tests/Integration/AnnotationReplyToTests.cs b/src/UglyToad.PdfPig.Tests/Integration/AnnotationReplyToTests.cs index 83660a43a..2a7e23755 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/AnnotationReplyToTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/AnnotationReplyToTests.cs @@ -16,9 +16,9 @@ public void HasCorrectNumberOfAnnotations() var page = document.GetPage(1); - var annotations = page.ExperimentalAccess.GetAnnotations().ToList(); + var annotations = page.GetAnnotations().ToArray(); - Assert.Equal(4, annotations.Count); + Assert.Equal(4, annotations.Length); Assert.Equal(AnnotationType.Text, annotations[0].Type); Assert.Equal(AnnotationType.Popup, annotations[1].Type); @@ -33,7 +33,7 @@ public void SecondTextReplyToFirst() var page = document.GetPage(1); - var annotations = page.ExperimentalAccess.GetAnnotations().ToList(); + var annotations = page.GetAnnotations().ToArray(); Assert.Equal(annotations[0], annotations[2].InReplyTo); } diff --git a/src/UglyToad.PdfPig.Tests/Integration/AnnotationsTest.cs b/src/UglyToad.PdfPig.Tests/Integration/AnnotationsTest.cs index cf3808f8c..2663d132e 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/AnnotationsTest.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/AnnotationsTest.cs @@ -11,7 +11,7 @@ public void AnnotationsHaveActions() using (var doc = PdfDocument.Open(pdf)) { - var annots = doc.GetPage(1).ExperimentalAccess.GetAnnotations().ToArray(); + var annots = doc.GetPage(1).GetAnnotations().ToArray(); Assert.Equal(5, annots.Length); Assert.All(annots, a => Assert.NotNull(a.Action)); Assert.All(annots, a => Assert.IsType(a.Action)); @@ -25,7 +25,7 @@ public void CheckAnnotationAppearanceStreams() var pdf = IntegrationHelpers.GetSpecificTestDocumentPath("appearances"); using (var doc = PdfDocument.Open(pdf)) { - var annotations = doc.GetPage(1).ExperimentalAccess.GetAnnotations().ToArray(); + var annotations = doc.GetPage(1).GetAnnotations().ToArray(); var annotation = Assert.Single(annotations); Assert.True(annotation.HasDownAppearance); diff --git a/src/UglyToad.PdfPig.Tests/Integration/CatGeneticsTests.cs b/src/UglyToad.PdfPig.Tests/Integration/CatGeneticsTests.cs index b8f5e7b3b..fa916f935 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/CatGeneticsTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/CatGeneticsTests.cs @@ -28,7 +28,7 @@ public void CanGetAnnotations() { var page = document.GetPage(1); - var annotations = page.ExperimentalAccess.GetAnnotations().ToList(); + var annotations = page.GetAnnotations().ToArray(); Assert.NotEmpty(annotations); diff --git a/src/UglyToad.PdfPig.Tests/Integration/ColorSpaceTests.cs b/src/UglyToad.PdfPig.Tests/Integration/ColorSpaceTests.cs index 0f70332e0..ee72b0179 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/ColorSpaceTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/ColorSpaceTests.cs @@ -285,7 +285,7 @@ public void SeparationLabColorSpace() { var page1 = document.GetPage(1); - var background = page1.ExperimentalAccess.Paths[0]; + var background = page1.Paths[0]; Assert.True(background.IsFilled); var (r, g, b) = background.FillColor.ToRGBValues(); @@ -327,7 +327,7 @@ public void SeparationIccColorSpacesWithForm() using (var document = PdfDocument.Open(path)) { Page page1 = document.GetPage(1); - var paths1 = page1.ExperimentalAccess.Paths.Where(p => p.IsFilled).ToArray(); + var paths1 = page1.Paths.Where(p => p.IsFilled).ToArray(); var reflexRed = paths1[0].FillColor.ToRGBValues(); // 'Reflex Red' Separation color space Assert.Equal(0.930496, reflexRed.r, 6); Assert.Equal(0.111542, reflexRed.g, 6); @@ -341,7 +341,7 @@ public void SeparationIccColorSpacesWithForm() Assert.Equal("w", firstLetter.Value); Assert.Equal((0, 0, 1), firstLetter.Color.ToRGBValues()); // Blue - var paths2 = page2.ExperimentalAccess.Paths; + var paths2 = page2.Paths; var filledPath = paths2.Where(p => p.IsFilled).ToArray(); var filledRects = filledPath.Where(p => p.Count == 1 && p[0].IsDrawnAsRectangle).ToArray(); diff --git a/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs b/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs index ac2950698..5defa8b3a 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs @@ -24,7 +24,7 @@ public void CanReadAllPages(string documentName) { var page = document.GetPage(i + 1); - Assert.NotNull(page.ExperimentalAccess.GetAnnotations().ToList()); + Assert.NotNull(page.GetAnnotations().ToArray()); } } } @@ -45,7 +45,7 @@ public void CanUseStreamForFirstPage(string documentName) { var page = document.GetPage(i + 1); - Assert.NotNull(page.ExperimentalAccess.GetAnnotations().ToList()); + Assert.NotNull(page.GetAnnotations().ToArray()); } } } diff --git a/src/UglyToad.PdfPig.Tests/Integration/OptionalContentTests.cs b/src/UglyToad.PdfPig.Tests/Integration/OptionalContentTests.cs index fe7d94a5e..fa52b3c2d 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/OptionalContentTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/OptionalContentTests.cs @@ -8,7 +8,7 @@ public void NoMarkedOptionalContent() using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("AcroFormsBasicFields.pdf"))) { var page = document.GetPage(1); - var oc = page.ExperimentalAccess.GetOptionalContents(); + var oc = page.GetOptionalContents(); Assert.Empty(oc); } @@ -20,7 +20,7 @@ public void MarkedOptionalContent() using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("odwriteex.pdf"))) { var page = document.GetPage(1); - var oc = page.ExperimentalAccess.GetOptionalContents(); + var oc = page.GetOptionalContents(); Assert.Equal(3, oc.Count); @@ -40,19 +40,19 @@ public void MarkedOptionalContentRecursion() using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("Layer pdf - 322_High_Holborn_building_Brochure.pdf"))) { var page1 = document.GetPage(1); - var oc1 = page1.ExperimentalAccess.GetOptionalContents(); + var oc1 = page1.GetOptionalContents(); Assert.Equal(16, oc1.Count); Assert.Contains("NEW ARRANGEMENT", oc1); var page2 = document.GetPage(2); - var oc2 = page2.ExperimentalAccess.GetOptionalContents(); + var oc2 = page2.GetOptionalContents(); Assert.Equal(15, oc2.Count); Assert.DoesNotContain("NEW ARRANGEMENT", oc2); Assert.Contains("WDL Shell text", oc2); Assert.Equal(2, oc2["WDL Shell text"].Count); var page3 = document.GetPage(3); - var oc3 = page3.ExperimentalAccess.GetOptionalContents(); + var oc3 = page3.GetOptionalContents(); Assert.Equal(15, oc3.Count); Assert.Contains("WDL Shell text", oc3); Assert.Equal(2, oc3["WDL Shell text"].Count); diff --git a/src/UglyToad.PdfPig.Tests/Integration/PatternColorTests.cs b/src/UglyToad.PdfPig.Tests/Integration/PatternColorTests.cs index 249724f6a..1d553701a 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/PatternColorTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/PatternColorTests.cs @@ -12,7 +12,7 @@ public void ShadingPattern1() { var page = document.GetPage(1); - var annotationStamp = page.ExperimentalAccess.GetAnnotations().ElementAt(14); + var annotationStamp = page.GetAnnotations().ElementAt(14); Assert.Equal(Annotations.AnnotationType.Stamp, annotationStamp.Type); Assert.True(annotationStamp.HasNormalAppearance); @@ -28,7 +28,7 @@ public void ShadingPattern2() using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("output_w3c_csswg_drafts_issues2023.pdf"))) { var page = document.GetPage(1); - var path = page.ExperimentalAccess.Paths.Single(); + var path = page.Paths.Single(); var color = path.FillColor; Assert.Equal(ColorSpace.Pattern, color.ColorSpace); @@ -55,7 +55,7 @@ public void TillingPattern1() using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("22060_A1_01_Plans-1.pdf"))) { var page = document.GetPage(1); - var filledPath = page.ExperimentalAccess.Paths.Where(p => p.IsFilled).ToArray(); + var filledPath = page.Paths.Where(p => p.IsFilled).ToArray(); var pattern = filledPath[0].FillColor; Assert.Equal(ColorSpace.Pattern, pattern.ColorSpace); @@ -100,7 +100,7 @@ public void TillingPattern2() { // page 53 var page = document.GetPage(53); - var strokedPath = page.ExperimentalAccess.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray(); + var strokedPath = page.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray(); Assert.Equal(5, strokedPath.Length); foreach (var p in strokedPath) { @@ -114,7 +114,7 @@ public void TillingPattern2() // page 307 page = document.GetPage(307); - strokedPath = page.ExperimentalAccess.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray(); + strokedPath = page.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray(); Assert.Equal(2, strokedPath.Length); foreach (var p in strokedPath) { diff --git a/src/UglyToad.PdfPig.Tests/Integration/RotationAndCroppingTests.cs b/src/UglyToad.PdfPig.Tests/Integration/RotationAndCroppingTests.cs index 39ddb34c4..6da1fac1d 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/RotationAndCroppingTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/RotationAndCroppingTests.cs @@ -32,7 +32,7 @@ public void WrongPathCount() { var page = document.GetPage(1); Assert.Equal(612, page.Height); - Assert.Equal(224, page.ExperimentalAccess.Paths.Count); + Assert.Equal(224, page.Paths.Count); } } diff --git a/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs b/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs index 551663237..0a2fd9e7b 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs @@ -171,7 +171,7 @@ private static void Run(string file, int imageHeight = 792, int pageNo = 1) DrawRectangle(letter.GlyphRectangle, graphics, violetPen, imageHeight, scale); } - foreach (var annotation in page.ExperimentalAccess.GetAnnotations()) + foreach (var annotation in page.GetAnnotations()) { DrawRectangle(annotation.Rectangle, graphics, bluePen, imageHeight, scale); } diff --git a/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs b/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs index 9ddd9683e..62d2bc676 100644 --- a/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs +++ b/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs @@ -115,16 +115,16 @@ public void CanFastAddPageAndStripLinkAnnots() output.AddPage(existing, 1); results = output.Build(); var pg = existing.GetPage(1); - var annots = pg.ExperimentalAccess.GetAnnotations().ToList(); - annotCount = annots.Count; + var annots = pg.GetAnnotations().ToArray(); + annotCount = annots.Length; Assert.Contains(annots, x => x.Type == Annotations.AnnotationType.Link); } using (var rewritten = PdfDocument.Open(results, ParsingOptions.LenientParsingOff)) { var pg = rewritten.GetPage(1); - var annots = pg.ExperimentalAccess.GetAnnotations().ToList(); - Assert.Equal(annotCount - 1, annots.Count); + var annots = pg.GetAnnotations().ToArray(); + Assert.Equal(annotCount - 1, annots.Length); Assert.DoesNotContain(annots, x => x.Type == Annotations.AnnotationType.Link); } } diff --git a/src/UglyToad.PdfPig.Tests/Writer/PdfMergerTests.cs b/src/UglyToad.PdfPig.Tests/Writer/PdfMergerTests.cs index 68794dfb3..08cd2c052 100644 --- a/src/UglyToad.PdfPig.Tests/Writer/PdfMergerTests.cs +++ b/src/UglyToad.PdfPig.Tests/Writer/PdfMergerTests.cs @@ -194,7 +194,7 @@ public void CanMergeWithLinks() using (var document = PdfDocument.Open(result, ParsingOptions.LenientParsingOff)) { Assert.Equal(2, document.GetPages().Sum( - page => page.ExperimentalAccess.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link))); + page => page.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link))); } } @@ -209,7 +209,7 @@ public void CanMergeWithLinksWithSelection() using (var document = PdfDocument.Open(result, ParsingOptions.LenientParsingOff)) { Assert.Equal(1, document.GetPages().Sum( - page => page.ExperimentalAccess.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link))); + page => page.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link))); } } diff --git a/src/UglyToad.PdfPig/Content/Page.cs b/src/UglyToad.PdfPig/Content/Page.cs index a8ff130a7..bd7eb3f85 100644 --- a/src/UglyToad.PdfPig/Content/Page.cs +++ b/src/UglyToad.PdfPig/Content/Page.cs @@ -83,9 +83,15 @@ public class Page /// public IReadOnlyList Operations => Content.GraphicsStateOperations; + /// + /// The set of s drawn by the PDF content. + /// + public IReadOnlyList Paths => Content?.Paths ?? Array.Empty(); + /// /// Access to members whose future locations within the API will change without warning. /// + [Obsolete("Use methods and properties directly at Page level.")] public Experimental ExperimentalAccess { get; } internal Page(int number, DictionaryToken dictionary, MediaBox mediaBox, CropBox cropBox, PageRotationDegrees rotation, @@ -119,7 +125,7 @@ internal Page(int number, DictionaryToken dictionary, MediaBox mediaBox, CropBox Height = viewBox.Height; Size = viewBox.GetPageSize(); - ExperimentalAccess = new Experimental(this, annotationProvider); + ExperimentalAccess = new Experimental(this); this.annotationProvider = annotationProvider; this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner)); } @@ -197,72 +203,92 @@ public IReadOnlyList GetHyperlinks() /// public IReadOnlyList GetMarkedContents() => Content.GetMarkedContents(); + /// + /// Get the annotation objects from the page. + /// + /// The lazily evaluated set of annotations on this page. + public IEnumerable GetAnnotations() + { + return annotationProvider.GetAnnotations(); + } + + /// + /// Gets any optional content on the page. + /// Does not handle XObjects and annotations for the time being. + /// + public IReadOnlyDictionary> GetOptionalContents() + { + List mcesOptional = new List(); + + // 4.10.2 + // Optional content in content stream + GetOptionalContentsRecursively(Content?.GetMarkedContents(), ref mcesOptional); + + // Optional content in XObjects and annotations + // TO DO + //var annots = GetAnnotations().ToList(); + + return mcesOptional.GroupBy(oc => oc.Name).ToDictionary(g => g.Key!, g => (IReadOnlyList)g.ToList()); + } + + private void GetOptionalContentsRecursively(IReadOnlyList? markedContentElements, ref List mcesOptional) + { + if (markedContentElements is null || markedContentElements.Count == 0) + { + return; + } + + foreach (var mce in markedContentElements) + { + if (mce.Tag == "OC") + { + mcesOptional.Add(new OptionalContentGroupElement(mce, pdfScanner)); + // we don't recurse + } + else if (mce.Children?.Count > 0) + { + GetOptionalContentsRecursively(mce.Children, ref mcesOptional); + } + } + } + /// /// Provides access to useful members which will change in future releases. /// + [Obsolete("Use methods and properties directly at Page level.")] public class Experimental { private readonly Page page; - private readonly AnnotationProvider annotationProvider; /// /// The set of s drawn by the PDF content. /// - public IReadOnlyList Paths => page.Content?.Paths ?? new List(); + [Obsolete("Use Page.Paths instead.")] + public IReadOnlyList Paths => page.Paths; - internal Experimental(Page page, AnnotationProvider annotationProvider) + internal Experimental(Page page) { this.page = page; - this.annotationProvider = annotationProvider; } /// /// Get the annotation objects from the page. /// /// The lazily evaluated set of annotations on this page. + [Obsolete("Use Page.GetAnnotations() instead.")] public IEnumerable GetAnnotations() { - return annotationProvider.GetAnnotations(); + return page.GetAnnotations(); } /// /// Gets any optional content on the page. /// Does not handle XObjects and annotations for the time being. /// + [Obsolete("Use Page.GetOptionalContents() instead.")] public IReadOnlyDictionary> GetOptionalContents() { - List mcesOptional = new List(); - - // 4.10.2 - // Optional content in content stream - GetOptionalContentsRecursively(page.Content?.GetMarkedContents(), ref mcesOptional); - - // Optional content in XObjects and annotations - // TO DO - //var annots = GetAnnotations().ToList(); - - return mcesOptional.GroupBy(oc => oc.Name).ToDictionary(g => g.Key!, g => (IReadOnlyList)g.ToList()); - } - - private void GetOptionalContentsRecursively(IReadOnlyList? markedContentElements, ref List mcesOptional) - { - if (markedContentElements is null || markedContentElements.Count == 0) - { - return; - } - - foreach (var mce in markedContentElements) - { - if (mce.Tag == "OC") - { - mcesOptional.Add(new OptionalContentGroupElement(mce, page.pdfScanner)); - // we don't recurse - } - else if (mce.Children?.Count > 0) - { - GetOptionalContentsRecursively(mce.Children, ref mcesOptional); - } - } + return page.GetOptionalContents(); } } }