|
1 | 1 | |
2 | 2 | namespace UglyToad.PdfPig.Writer |
3 | 3 | { |
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; |
10 | 5 | using Content; |
11 | 6 | using Core; |
12 | | - using Fonts; |
13 | | - using Actions; |
14 | 7 | using Filters; |
| 8 | + using Fonts; |
15 | 9 | using Graphics; |
16 | 10 | using Logging; |
17 | | - using PdfPig.Fonts.TrueType; |
18 | | - using PdfPig.Fonts.Standard14Fonts; |
19 | | - using PdfPig.Fonts.TrueType.Parser; |
20 | 11 | using Outline; |
21 | 12 | using Outline.Destinations; |
22 | 13 | using Parser; |
23 | 14 | 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; |
24 | 24 | using Tokenization.Scanner; |
25 | 25 | using Tokens; |
26 | 26 |
|
@@ -307,7 +307,6 @@ private sealed class PageInfo(DictionaryToken page, IReadOnlyList<DictionaryToke |
307 | 307 | /// </summary> |
308 | 308 | /// <param name="document">Source document.</param> |
309 | 309 | /// <param name="pageNumber">Page to copy.</param> |
310 | | - /// <param name="options">Control how copying for the page occurs.</param> |
311 | 310 | /// <returns>A builder for editing the page.</returns> |
312 | 311 | public PdfPageBuilder AddPage(PdfDocument document, int pageNumber) |
313 | 312 | { |
@@ -463,7 +462,9 @@ public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, AddPageOptio |
463 | 462 | kvp.Value, |
464 | 463 | document.Structure.TokenScanner, |
465 | 464 | refs, |
466 | | - options.CopyLinkFunc); |
| 465 | + page, |
| 466 | + options.CopyLinkFunc, |
| 467 | + x => links.Add(x)); |
467 | 468 |
|
468 | 469 | copiedPageDict[NameToken.Annots] = new ArrayToken(copiedTokens); |
469 | 470 | continue; |
@@ -571,7 +572,9 @@ private IReadOnlyList<IToken> CopyAnnotationsFromPageSource( |
571 | 572 | IToken val, |
572 | 573 | IPdfTokenScanner sourceScanner, |
573 | 574 | IDictionary<IndirectReference, IndirectReferenceToken> refs, |
574 | | - Func<PdfAction, PdfAction?>? linkCopyFunc) |
| 575 | + Page page, |
| 576 | + Func<PdfAction, PdfAction?>? linkCopyFunc = null, |
| 577 | + Action<(DictionaryToken, PdfAction)>? deferredActionUpdate = null) |
575 | 578 | { |
576 | 579 | var permittedLinkActionTypes = new HashSet<NameToken> |
577 | 580 | { |
@@ -630,10 +633,22 @@ private IReadOnlyList<IToken> CopyAnnotationsFromPageSource( |
630 | 633 | continue; |
631 | 634 | } |
632 | 635 |
|
633 | | - // Todo copy |
634 | | - // var copiedLogicOverride = linkCopyFunc() |
| 636 | + if (linkCopyFunc != null && deferredActionUpdate != null) |
| 637 | + { |
| 638 | + var action = page.annotationProvider.GetAction(annotDict); |
635 | 639 |
|
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 | + } |
637 | 652 |
|
638 | 653 | // If the link has an action then this link can point elsewhere in this document, maybe not to a page we copied? |
639 | 654 | if (annotDict.TryGet(NameToken.A, sourceScanner, out DictionaryToken? actionDict)) |
|
0 commit comments