10

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/");
BotanMan
  • 1,357
  • 12
  • 25

2 Answers2

14

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.

BotanMan
  • 1,357
  • 12
  • 25
2

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

  • ThomasH, I tried to use it before, but there is no links in a document! (} var paragraph = section.AddParagraph("test link"); paragraph.AddHyperlink("http://stackoverflow.com/", HyperlinkType.Web); – BotanMan Oct 02 '13 at 07:31
  • 1
    @BotanMan The AddXxx functions usually return a newly created object, so it's generally a good idea to check the return type. The MigraDoc samples also show how to use AddHyperlink, just see the samples site: http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx?HL=addhyperlink – I liked the old Stack Overflow Oct 02 '13 at 08:11
  • @PDFsharp Team Yes, I found the documentation) Thanks! But I think I done it without googling if there were some comments to a method args, and why do not add separate constructor with initializing some content like a text? – BotanMan Oct 09 '13 at 07:34