PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Important Notice: We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024. If you wish to migrate to our paid hosting service, please contact billing@hostonnet.com.
Add a link on Page in PDFSharp *SOLVED*

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
PeterHallengreen



Joined: 23 Sep 2008
Posts: 2

PostPosted: Tue Sep 23, 2008 1:17 pm    Post subject: Add a link on Page in PDFSharp *SOLVED* Reply with quote

Hi All,

As the documentation is a "bit" missing in most of the core of PDFSharp, I couldnt get the gfx.PdfPage.AddWebLink(PDFRectangle, url) to work.

The solution was not in this forum, and therefore after several tries, and drawing lots of rectangles, I realized it uses the normal coordinate system, as it does native in PDF.
And not like anywhere else in PDFSharp, where the GDI-coordinate-system is used.

So I you want to add a WebLink, FileLink or DocumentLink , you have to "invert" the Y-position like this :



Code:

double height = PdfSharp.PageSizeConverter.ToSize((PdfSharp.PageSize)m_CurrentPDFPage.Size).Height;

PdfSharp.Pdf.PdfRectangle rc = new PdfSharp.Pdf.PdfRectangle(new PdfSharp.Drawing.XPoint(position.X, height - position.Y), new PdfSharp.Drawing.XPoint(position.X + size.Width, height - (position.Y + size.Height)));
gfx.PdfPage.AddWebLink(rc, url);
Back to top
View user's profile Send private message
PeterHallengreen



Joined: 23 Sep 2008
Posts: 2

PostPosted: Wed Sep 24, 2008 7:54 am    Post subject: Reply with quote

Found a function that did the trick.
gfx.Transformer.WorldToDefaultPage

Code:

// Convert rectangle form world space to page space. This is necessary because the weblink is
// placed relative to the bottom left corner of the page with units measured in point.
PdfSharp.Drawing.XRect rect = gfx.Transformer.WorldToDefaultPage(new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(position.X, position.Y), size));
PdfSharp.Pdf.PdfRectangle rc = new PdfSharp.Pdf.PdfRectangle(rect);
gfx.PdfPage.AddWebLink(rc, url);
gfx.Dispose();
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com