From 6e0caee317976f5c45c4049f8ace8d7701883284 Mon Sep 17 00:00:00 2001 From: Inusual Date: Mon, 24 Feb 2020 21:07:23 -0400 Subject: [PATCH] Add StreamToken as exception to CopyTokenq Add summary to better explain CopyToken purpose --- src/UglyToad.PdfPig/Writer/PdfMerger.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/UglyToad.PdfPig/Writer/PdfMerger.cs b/src/UglyToad.PdfPig/Writer/PdfMerger.cs index 186fc658..e059c7a2 100644 --- a/src/UglyToad.PdfPig/Writer/PdfMerger.cs +++ b/src/UglyToad.PdfPig/Writer/PdfMerger.cs @@ -264,6 +264,13 @@ return Context.WriteObject(Memory, new DictionaryToken(pageDictionary)); } + /// + /// The purpose of this method is to resolve indirect reference. That mean copy the reference's content to the new document's stream + /// and replace the indirect reference with the correct/new one + /// + /// Token to inspect for reference + /// scanner get the content from the original document + /// A copy of the token with all his content copied to the new document's stream private IToken CopyToken(IToken tokenToCopy, IPdfTokenScanner tokenScanner) { if (tokenToCopy is DictionaryToken dictionaryToken) @@ -301,11 +308,14 @@ } else if (tokenToCopy is StreamToken streamToken) { - return streamToken; + //Note: Unnecessary + var properties = CopyToken(streamToken.StreamDictionary, tokenScanner) as DictionaryToken; + Debug.Assert(properties != null); + return new StreamToken(properties, new List(streamToken.Data)); } else // Non Complex Token - BooleanToken, NumericToken, NameToken, Etc... { - // TODO: Should we do a deep copy of the token? + // TODO: Should we do a deep copy of this tokens? return tokenToCopy; } }