PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 4:16 pm

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 Sep 23, 2008 1:17 pm 
Offline

Joined: Tue Sep 23, 2008 1:05 pm
Posts: 2
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);


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

Joined: Tue Sep 23, 2008 1:05 pm
Posts: 2
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();


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 04, 2012 10:10 am 
Offline

Joined: Wed Jan 04, 2012 10:08 am
Posts: 1
This solution should be added to the Wiki. Been searching for it for hours.

Thanks PeterHallengreen

_________________
--
Dan Journo
Kesher Communications Ltd
https://www.kesher.com/


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 49 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