PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

WebLink or Hyperlink in a PDF Document
http://forum.pdfsharp.com/viewtopic.php?f=2&t=2059
Page 1 of 1

Author:  dsevans [ Mon Jun 18, 2012 5:46 pm ]
Post subject:  WebLink or Hyperlink in a PDF Document

I am trying to figure out how to add a simple hyperlink or weblink (not sure what the diff is) onto my pdf document.
Here is my code. in the end i would prefer a link that goes to Google.Com and has text Click Here for Goolge.
I can't find any good examples of how to do this. :(

using (XGraphics gfx = XGraphics.FromPdfPage(page))
{
XRect rec = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 60), new XSize(30, 30)));
PdfRectangle rect = new PdfRectangle(rec);

PdfLinkAnnotation link = PdfLinkAnnotation.CreateWebLink(rect, "www.google.com");
page.Annotations.Add(link);

page.AddWebLink(rect, "www.google.com");
gfx.DrawRectangle(XPens.Black, XBrushes.Black, link.ToString());
}

Author:  Thomas Hoevel [ Tue Jun 19, 2012 9:18 am ]
Post subject:  Re: WebLink or Hyperlink in a PDF Document

AddWebLink is the way to go. All AddWebLink does is create a clickable area where Adobe Reader shows a different cursor.
It's up to you to draw text or a frame at that area.

So maybe your link is already working, but you don't see it until you move the mouse to the right spot.

See also:
viewtopic.php?p=3804#p3804

With MigraDoc you would use AddHyperlink. You specify the text for the hyperlink, MigraDoc calculates the rectangle.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/