Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a link to a file in PdfSharp?

Tags:

c#

.net

pdfsharp

I can't seem to get PdfSharp to show a picture for this annotation. It doesn't have the PdfAnnotation.Icon property, so I can't set that.

XFont font = new XFont("Verdana", 10);
PdfPage page = wDoc.Parent.Page;
XGraphics gfx = wDoc.Parent.gfx;
XRect rec = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 60), new XSize(30, 30)));
PdfRectangle rect = new PdfRectangle(rec);
PdfLinkAnnotation link = PdfLinkAnnotation.CreateFileLink(rect, wDoc.FileLocation);
gfx.DrawString("These files were attached:", font, XBrushes.Black, 30, 50, XStringFormat.Default);

link.Rectangle = new PdfRectangle(rec);
page.Annotations.Add(link);

I've gotten it that far, and the annotation DOES exist, except it's a blank box! How do I go about making it say something, or even just show a picture?


1 Answers

You need to use page.AddWebLink(AREArect) and then add the text area with gfx.drawstring(AREArect)

like image 146
John Avatar answered Sep 03 '25 13:09

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!