PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Apr 15, 2021 1:13 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Jun 22, 2016 8:13 pm 

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 26
While working on a library, that merges multiple Pdf-Documents, i observed an odd behavior when the imported Pages contained Document-Links. (Link-Annotations)

Beside from the links not working at all in the final document, i found out, the links were still referencing a page from the original document, that was imported.
Further debugging revealed, the pages from the original document were all present in the final document (and therefore duplicates) as well as the /Pages-Array of the original document.

This was observed using PdfSharp 1.32, but a quick look at the 1.50 source-code suggests, the problem is still present there.

I was able to work around this issue by writing a small utility-function

        private void FixLinkAnnotations(PdfPage page, PdfDocument doc, int pageOffset)
            for (var i = 0; i < page.Annotations.Count; i++)
                var annot = page.Annotations[i];
                var subType = annot.Elements.GetString(PdfAnnotation.Keys.Subtype);
                if (subType == "/Link")
                    var dest = annot.Elements.GetArray("/Dest");    // may also be a named destination
                    var rect = annot.Elements.GetRectangle(PdfAnnotation.Keys.Rect);
                    if (dest != null && rect != null && dest.Elements.Count > 0)
                        var targetPage = dest.Elements.GetReference(0);
                        for (var p = 0; p < doc.PageCount; p++)
                            if (doc.Pages[p].Reference == targetPage)
                                page.Annotations.Elements[i] = PdfLinkAnnotation.CreateDocumentLink(rect, p + pageOffset);
                                // TODO: copy additional properties from original annotation ?


Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group