PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 12:02 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Jun 25, 2013 6:49 pm 
Offline

Joined: Thu Jun 13, 2013 7:28 pm
Posts: 2
I am trying to build a TOC using PdfSharp and while I can add the elements where I would like them, I can't get the document links to line up with the TOC elements like I expect they should. See the following code for an example:
Code:
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();

XGraphics gfx = XGraphics.FromPdfPage(page);
XRect rect = new XRect(5, 5, 500, 20);
PdfRectangle prect = new PdfRectangle(rect);

page.AddDocumentLink(prect, 1);
gfx.DrawRectangle(XBrushes.Transparent, rect);

doc.Save(@"C:\test.pdf");


With the code above I would place the text of my TOC element inside 'rect' and then clicking on that rectangle should link to the page of the document. However, the AddDocumentLink method is not placing that link at the same place on the page as the DrawRectangle is. It's placing it at the bottom. You can see the attached example document to see what is happening.

Thank you for any help with this,

Jon


Attachments:
test.zip [978 Bytes]
Downloaded 438 times
Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 26, 2013 8:21 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
The MigraDoc renderer includes the following line:
Code:
XRect rect = this.gfx.Transformer.WorldToDefaultPage(this.hyperlinkRect);

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 26, 2013 1:54 pm 
Offline

Joined: Thu Jun 13, 2013 7:28 pm
Posts: 2
That did the trick, thank you.

Code:
PdfRectangle prect = new PdfRectangle(gfx.Transformer.WorldToDefaultPage(rect));

page.AddDocumentLink(prect, 1);


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 328 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group