PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Apr 18, 2013 5:42 pm 
Offline

Joined: Fri Apr 05, 2013 6:42 pm
Posts: 10
I'm adding my bookmarks via MirgrDoc like so:

Code:
       '...
       paragraph.AddBookmark(text)
       paragraph.Format.OutlineLevel = Level1
       paragraph.ExpandOutline = false
       '...


After the document is rendered and saved, when I open it and click on bookmarks, if more than one are on the same page it jumps to the top of the page every time. If I add a bookmark my self to the document (manually) it will jump to that specific spot on the page.

How do I get the paragraph's bookmark to behave in that manner?
Well really, get the Outline link to behave in that manner I guess...



Thanks,

Justin


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 19, 2013 2:05 pm 
Offline

Joined: Fri Apr 05, 2013 6:42 pm
Posts: 10
I've looked into this issue more and have found that (at this point) it's just a limitation of the API.

Justin


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 06, 2014 4:45 pm 
Offline

Joined: Thu Mar 06, 2014 4:35 pm
Posts: 2
Hi
I'm having also problem with using outlines in .pdf as they are not pointing directly to desired items, but only to page start (sometimes even that fails when page is scrolled down a bit before pressing bookmark).
I've seen more topics about this:
viewtopic.php?f=2&t=2295&hilit=outline
viewtopic.php?f=2&t=1298&hilit=outline
, but all without relevant response.
If it's limitation of API, can someone point me to right direction how to achieve adding this page offset into outline?
Current outline implementation is kind of useless with multiple topics in same page..
Thanks for any help here..


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2014 1:16 pm 
Offline

Joined: Thu Mar 06, 2014 4:35 pm
Posts: 2
Managed to get something working.
Here is some guide (for PdfSharp) in case some people would like to have outlines jumping to specific places.
In file PdfOutline.cs:
add variable with property
Code:
    /// <summary>
    /// Gets or sets the page offset (0 is top).
    /// </summary>
    public double PageOffset
    {
        get { return this.pageOffset; }
        set { this.pageOffset = value; }
    }
    double pageOffset;

Then in method PrepareForSave()
change line:
Code:
new PdfLiteral("/XYZ null null 0"));

to
Code:
new PdfLiteral(string.Format("/XYZ null {0} 0", DestinationPage.Height - 1.0 - PageOffset)));


You can add new overloaded constructors with new pageOffset value.


Top
 Profile  
Reply with quote  
PostPosted: Tue May 13, 2014 7:11 pm 
Offline

Joined: Thu Jan 10, 2013 8:29 pm
Posts: 10
Perfect hint, thank you.

I've also adapted:
Render() in ParagraphRenderer.cs

Code:
if ((int)this.paragraph.Format.OutlineLevel >= 1 && this.gfx.PdfPage != null) // Don't call GetOutlineTitle() in vain
        this.documentRenderer.AddOutline((int)this.paragraph.Format.OutlineLevel,
          GetOutlineTitle(), this.gfx.PdfPage, this.currentYPosition);


With this I get the exact behaviour I needed. The outline direct points to chapter title.
Perhaps some offset should be added (because it is not that beautiful).

Oh, and I also changed to int here, because I got "comma" separated and this destroyed the outlines.
Code:
new PdfLiteral(String.Format("/XYZ null {0} 0",(int)(DestinationPage.Height - 1.0 - PageOffset))));

I don't do any rounding because the values are nevertheless in the 840 range for A4 sheet.

One question to admins:
Is there a plan to collect all the "user provided changes and fixes" and release a 1.32-user-edition or something likely.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 14, 2014 5:17 am 
Offline

Joined: Thu Jan 10, 2013 8:29 pm
Posts: 10
Unfortunately it is working for Outlines but not for BookmarkFields.
I am trying to debug BookmarkField mechanism, but I don't understand it. :(

But at least I have perfect working Outlines :)


Top
 Profile  
Reply with quote  
PostPosted: Wed May 14, 2014 9:19 pm 
Offline

Joined: Thu Jan 10, 2013 8:29 pm
Posts: 10
I finally found a way to get also Bookmarks working as expected.

In PdfLinkAnnotation function WriteObject
Code:
  Elements[Keys.Dest] = new PdfLiteral("[{0} 0 R/XYZ null {1} 0]", dest.ObjectNumber, offset_pts);


if extending the following function with this third parameter, will automatically let the compiler tell you,
where to change.
Code:
public static PdfLinkAnnotation CreateDocumentLink(PdfRectangle rect, int destinationPage, int offset_pts)
{


In the end, the last change should be:
Code:
FormatResult FormatBookmarkField(BookmarkField bookmarkField)
{
  this.fieldInfos.AddBookmark(bookmarkField.Name,(int)this.currentYPosition.Point);
  return FormatResult.Ignore;
}


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

All times are UTC


Who is online

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