From 5a6b3970f0e3544e883ea46bf9df15eb9303cd53 Mon Sep 17 00:00:00 2001 From: ricflams Date: Mon, 29 Sep 2025 17:46:52 +0200 Subject: [PATCH] Add table-xref's associated stream-xrefs - If an XrefTable has an associated stream, as indicated via the XrefStm-property, then read and add that XrefStream - Any table can have 0 or 1 such associated streams - A caveat: such an associated stream might also theoretically be part of the Parts-sequence in which case it would be encountered both by looping through all those parts along with all the regular tables and now also by association to any of those tables. It doesn't seem harmful since the offsets are flattened eventually anyway and stored by their offset-key into a mapping-table. --- .../Parser/FileStructure/FirstPassParser.cs | 17 +++++++++++++++++ .../Parser/FileStructure/XrefTable.cs | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/UglyToad.PdfPig/Parser/FileStructure/FirstPassParser.cs b/src/UglyToad.PdfPig/Parser/FileStructure/FirstPassParser.cs index 07802351..a0b847e3 100644 --- a/src/UglyToad.PdfPig/Parser/FileStructure/FirstPassParser.cs +++ b/src/UglyToad.PdfPig/Parser/FileStructure/FirstPassParser.cs @@ -153,6 +153,23 @@ internal static partial class FirstPassParser { results.Add(table); nextLocation = table.GetPrevious(); + + // Also add any optional associated Stream + var xRefStm = table.GetXRefStm(); + if (xRefStm is long xRefStmValue) + { + var stream = GetXrefStreamOrTable( + offset, + input, + scanner, + xRefStmValue, + log); + + if (stream != null) + { + results.Add(stream); + } + } } else if (streamOrTable is XrefStream stream) { diff --git a/src/UglyToad.PdfPig/Parser/FileStructure/XrefTable.cs b/src/UglyToad.PdfPig/Parser/FileStructure/XrefTable.cs index c02a1aa8..011b25ba 100644 --- a/src/UglyToad.PdfPig/Parser/FileStructure/XrefTable.cs +++ b/src/UglyToad.PdfPig/Parser/FileStructure/XrefTable.cs @@ -44,4 +44,14 @@ internal sealed class XrefTable : IXrefSection return null; } + + public long? GetXRefStm() + { + if (Dictionary != null && Dictionary.TryGet(NameToken.XrefStm, out NumericToken xRefStm)) + { + return xRefStm.Long; + } + + return null; + } } \ No newline at end of file