Question

I have an odd problem while trying to render a Weblink on a PDF using Migradoc.

Paragraph hotelP = cell.AddParagraph(offer.Hotel.CompanyName.ToString());
hotelP.AddLineBreak();
Hyperlink hyperlink = hotelP.AddHyperlink(String.IsNullOrEmpty(offer.Hotel.Link) ? "" : offer.Hotel.Link, HyperlinkType.Web);
hyperlink.AddFormattedText(String.IsNullOrEmpty(offer.Hotel.Link) ? "" : offer.Hotel.Link.ToString(), "WebLink");

While this renders correctly, the link that it tries to hit is a file link in the file:///...bin/Debug(or Release)/www.theActualLink.org folder of the Project.

Any idea why this is happening? The code snippet should be the correct way of doing this, according to the PDFSharp Forums.

EDIT: Ok thanks to Thomas, I've changed the code to:

if (!String.IsNullOrEmpty(offer.Hotel.Link))
{
     Hyperlink hyperlink = hotelP.AddHyperlink("http://" + offer.Hotel.Link, HyperlinkType.Web);
     hyperlink.AddFormattedText(offer.Hotel.Link, "WebLink");
}

This is not the final code, but it now works because of the "http://" prefix on the link. Cheers!

Was it helpful?

Solution

Does offer.Hotel.Link include "http://" or "https://"? This could make the difference.

What's the point of calling AddHyperlink() when the URL is empty?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top