PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Add a link on Page in PDFSharp *SOLVED* https://forum.pdfsharp.net/viewtopic.php?f=2&t=487 |
Page 1 of 1 |
Author: | PeterHallengreen [ 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); |
Author: | PeterHallengreen [ 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(); |
Author: | DanJourno [ Wed Jan 04, 2012 10:10 am ] |
Post subject: | Re: Add a link on Page in PDFSharp *SOLVED* |
This solution should be added to the Wiki. Been searching for it for hours. Thanks PeterHallengreen |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |