BotanMan
BotanMan

Reputation: 1417

Adding links to pdf by using MigraDoc

I use MigraDoc for creating pdf documents in the project.

Code below shows how I work with library:

        var document = new Document { Info = { Author = "title" } };
        Section section = document.AddSection();
        Paragraph paragraph = section.AddParagraph("Title");
        var renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always) { Document = document };
        renderer.RenderDocument();

So, I'm looking for a way to adding link to web resource inside pdf.

Does someone know?)

-------------Solution-------------------

I found solution!

I tried to use AddHyperlink() for adding link, and it was the first step for this. The code below shows correct using:

        var h = paragraph.AddHyperlink("http://stackoverflow.com/",HyperlinkType.Web);
        h.AddFormattedText("http://www.stackoverflow.com/");

Upvotes: 10

Views: 6421

Answers (3)

Brian McLaughlin
Brian McLaughlin

Reputation: 7

This solution worked for me where declaring a new var of type Hyperlink threw a "'Rectangle' must not be null here." exception.

YourParagraph.AddHyperlink("patriots.win", HyperlinkType.Url).AddFormattedText("Red Pill", _hyperLink);

Upvotes: -1

BotanMan
BotanMan

Reputation: 1417

To add a link use AddHyperlink():

    var h = paragraph.AddHyperlink("http://stackoverflow.com/",HyperlinkType.Web);
    h.AddFormattedText("http://www.stackoverflow.com/");

So the idea that you should add some text for a link to make link visible.

Upvotes: 15

Use paragraph.AddHyperlink() for that purpose. You will need HyperlinkType.Web.

Upvotes: 2

Related Questions