PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 8:01 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Nov 26, 2009 11:15 am 
Offline

Joined: Thu Nov 26, 2009 10:13 am
Posts: 3
Hello, All

Thank you for the good job, like it a lot, but you know... bugs happen. I think there is a bug in PdfLinkAnnotation

Description & Reason

If you add a PdfLinkAnnotation pointing to the 1st document page, you will not be able to save the document.

PdfLinkAnnotation.WriteObject(PdfWriter writer) will try to get the -1st (negative) page of the document, which in turn yields ArgumentOutOfBoundsException:
Code:
...
case LinkType.Document:
          // destIndex > Owner.PageCount can happen rendering pages using PDFsharp directly
          int destIndex = this.destPage;
          if (destIndex > Owner.PageCount)
            destIndex = Owner.PageCount;
          destIndex--;
dest = this.Owner.Pages[destIndex];
...

"destIndex--" looks like a typo here, probably the original idea was like this:
Code:
...
case LinkType.Document:
          // destIndex > Owner.PageCount can happen rendering pages using PDFsharp directly
          int destIndex = this.destPage;
          if (destIndex > Owner.PageCount)
          {
                     destIndex = Owner.PageCount;
                     destIndex--;
          }

          dest = this.Owner.Pages[destIndex];
...


with best regards,
Alexey

Code to Reproduce the Bug
I have tested on the latest sources, .NET 2.0 flavour. Should fail in any flavour.
Code:
        public static void ReproduceFirstPageLinkBug()
        {
            PdfDocument     document;
            PdfPage         firstPage;
            PdfPage         secondPage;
            PdfAnnotation   linkToFirstPage;

            document = new PdfDocument();

            firstPage  = document.AddPage();
            secondPage = document.AddPage();

            linkToFirstPage = PdfLinkAnnotation.CreateDocumentLink(secondPage.MediaBox, 0);

            secondPage.Annotations.Add(linkToFirstPage);

            using (MemoryStream stream = new MemoryStream(1024))
            {
                document.Save(stream);
            }
        }


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 12:08 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!
bergamot wrote:
"destIndex--" looks like a typo here, probably the original idea was like this: [...]

I must check this.

I guess the idea was to convert from 1-based page number to 0-based page index.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 27, 2009 1:36 pm 
Offline

Joined: Thu Nov 26, 2009 10:13 am
Posts: 3
Oh, yes, you a right, Thomas. That might be a feature as well. So, is it 1-based or 0-based after all?


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 30, 2009 2:00 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

MigraDoc Online Help wrote:
destinationPage
Type: System.Int32
The one-based destination page number.


The code is mainly correct ...
... but future releases will throw an exception if CreateDocumentLink is called with a page number less than 1.
Pass 1 (not 0) to link to the first page.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 414 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