@@ -307,21 +307,21 @@ private sealed class PageInfo(DictionaryToken page, IReadOnlyList<DictionaryToke
307307 /// </summary>
308308 /// <param name="document">Source document.</param>
309309 /// <param name="pageNumber">Page to copy.</param>
310- /// <param name="keepAnnotations">Flag to set whether annotation of page should be kept </param>
310+ /// <param name="options">Control how copying for the page occurs. </param>
311311 /// <returns>A builder for editing the page.</returns>
312- public PdfPageBuilder AddPage ( PdfDocument document , int pageNumber , bool keepAnnotations = true )
312+ public PdfPageBuilder AddPage ( PdfDocument document , int pageNumber )
313313 {
314- return AddPage ( document , pageNumber , null ) ;
314+ return AddPage ( document , pageNumber , new AddPageOptions ( ) ) ;
315315 }
316316
317317 /// <summary>
318318 /// Add a new page with the specified size, this page will be included in the output when <see cref="Build"/> is called.
319319 /// </summary>
320320 /// <param name="document">Source document.</param>
321321 /// <param name="pageNumber">Page to copy.</param>
322- /// <param name="copyLink">If set, links are copied based on the result of the delegate .</param>
322+ /// <param name="options">Control how copying for the page occurs .</param>
323323 /// <returns>A builder for editing the page.</returns>
324- public PdfPageBuilder AddPage ( PdfDocument document , int pageNumber , Func < PdfAction , PdfAction ? > ? copyLink )
324+ public PdfPageBuilder AddPage ( PdfDocument document , int pageNumber , AddPageOptions options )
325325 {
326326 if ( ! existingCopies . TryGetValue ( document . Structure . TokenScanner , out var refs ) )
327327 {
@@ -454,7 +454,7 @@ public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, Func<PdfActi
454454
455455 if ( kvp . Key == NameToken . Annots )
456456 {
457- if ( ! keepAnnotations )
457+ if ( ! options . KeepAnnotations )
458458 {
459459 continue ;
460460 }
@@ -490,7 +490,7 @@ public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, Func<PdfActi
490490
491491 if ( tk . TryGet ( NameToken . Subtype , out var st ) && st is NameToken nm && nm == NameToken . Link )
492492 {
493- if ( copyLink is null )
493+ if ( options . CopyLinkFunc is null )
494494 {
495495 // ignore link if don't know how to copy
496496 continue ;
@@ -503,7 +503,7 @@ public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, Func<PdfActi
503503 continue ;
504504 }
505505
506- var copiedLink = copyLink ( link ) ;
506+ var copiedLink = options . CopyLinkFunc ( link ) ;
507507 if ( copiedLink is null )
508508 {
509509 // ignore if caller wants to skip the link
@@ -1248,5 +1248,21 @@ public void Dispose()
12481248
12491249 context . Dispose ( ) ;
12501250 }
1251+
1252+ /// <summary>
1253+ /// Options for how a page should be copied to the current builder when using AddPage.
1254+ /// </summary>
1255+ public class AddPageOptions
1256+ {
1257+ /// <summary>
1258+ /// Whether to preserve annotation objects in the copied page.
1259+ /// </summary>
1260+ public bool KeepAnnotations { get ; set ; } = true ;
1261+
1262+ /// <summary>
1263+ /// Intercept how actions are copied from the source to destination page.
1264+ /// </summary>
1265+ public Func < PdfAction , PdfAction ? > ? CopyLinkFunc { get ; set ; }
1266+ }
12511267 }
12521268}
0 commit comments