Skip to content

Commit 50f878b

Browse files
EliotJonesBobLd
authored andcommitted
restore copy link func logic
1 parent 2a10b6c commit 50f878b

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11

22
namespace UglyToad.PdfPig.Writer
33
{
4-
using System;
5-
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Linq;
8-
using System.Runtime.CompilerServices;
9-
using System.Xml.Linq;
4+
using Actions;
105
using Content;
116
using Core;
12-
using Fonts;
13-
using Actions;
147
using Filters;
8+
using Fonts;
159
using Graphics;
1610
using Logging;
17-
using PdfPig.Fonts.TrueType;
18-
using PdfPig.Fonts.Standard14Fonts;
19-
using PdfPig.Fonts.TrueType.Parser;
2011
using Outline;
2112
using Outline.Destinations;
2213
using Parser;
2314
using Parser.Parts;
15+
using PdfPig.Fonts.Standard14Fonts;
16+
using PdfPig.Fonts.TrueType;
17+
using PdfPig.Fonts.TrueType.Parser;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.IO;
21+
using System.Linq;
22+
using System.Runtime.CompilerServices;
23+
using System.Xml.Linq;
2424
using Tokenization.Scanner;
2525
using Tokens;
2626

@@ -307,7 +307,6 @@ 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="options">Control how copying for the page occurs.</param>
311310
/// <returns>A builder for editing the page.</returns>
312311
public PdfPageBuilder AddPage(PdfDocument document, int pageNumber)
313312
{
@@ -463,7 +462,9 @@ public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, AddPageOptio
463462
kvp.Value,
464463
document.Structure.TokenScanner,
465464
refs,
466-
options.CopyLinkFunc);
465+
page,
466+
options.CopyLinkFunc,
467+
x => links.Add(x));
467468

468469
copiedPageDict[NameToken.Annots] = new ArrayToken(copiedTokens);
469470
continue;
@@ -571,7 +572,9 @@ private IReadOnlyList<IToken> CopyAnnotationsFromPageSource(
571572
IToken val,
572573
IPdfTokenScanner sourceScanner,
573574
IDictionary<IndirectReference, IndirectReferenceToken> refs,
574-
Func<PdfAction, PdfAction?>? linkCopyFunc)
575+
Page page,
576+
Func<PdfAction, PdfAction?>? linkCopyFunc = null,
577+
Action<(DictionaryToken, PdfAction)>? deferredActionUpdate = null)
575578
{
576579
var permittedLinkActionTypes = new HashSet<NameToken>
577580
{
@@ -630,10 +633,22 @@ private IReadOnlyList<IToken> CopyAnnotationsFromPageSource(
630633
continue;
631634
}
632635

633-
// Todo copy
634-
// var copiedLogicOverride = linkCopyFunc()
636+
if (linkCopyFunc != null && deferredActionUpdate != null)
637+
{
638+
var action = page.annotationProvider.GetAction(annotDict);
635639

636-
//var link = page.annotationProvider.GetAction(tk);
640+
if (action != null)
641+
{
642+
var copiedLink = linkCopyFunc(action);
643+
if (copiedLink != action && copiedLink != null)
644+
{
645+
// defer to write links when all pages are added
646+
var copiedToken = (DictionaryToken)WriterUtil.CopyToken(context, annotDict, sourceScanner, refs);
647+
deferredActionUpdate((copiedToken, copiedLink));
648+
continue;
649+
}
650+
}
651+
}
637652

638653
// If the link has an action then this link can point elsewhere in this document, maybe not to a page we copied?
639654
if (annotDict.TryGet(NameToken.A, sourceScanner, out DictionaryToken? actionDict))

0 commit comments

Comments
 (0)