|
PDFsharp - moved to http://forum.pdfsharp.net/ Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
|
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.
View previous topic :: View next topic |
Author |
Message |
PeterHallengreen
Joined: 23 Sep 2008 Posts: 2
|
Posted: Tue Sep 23, 2008 1:17 pm Post subject: Add a link on Page in PDFSharp *SOLVED* |
|
|
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 |
|
|
PeterHallengreen
Joined: 23 Sep 2008 Posts: 2
|
Posted: Wed Sep 24, 2008 7:54 am Post subject: |
|
|
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 |
|
|
|
|
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
|
|