HTML Converter Base Tags

You are not limited to converting HTML from a URL, a local directory, or an HTML string. You can also combine all three if you convert using base tags.

Base Tag

The <base> tag specifies a base URI, or URL, that you use with relative paths. For example, if you specified

<base href=""> + <a href="forums">Forums</a>

then it would resolve as

when rendering the Forums link in the PDF. You must use a base tag when combining local and web resources using HTML Converter.

Image from URL and Local HTML

The following HTML illustrates. In this example the HTML is a string, while the base href and the image img tags are URLs. When converting the HTML string, the base tag also resolves the URLs to provide a complete document before converting to PDF.

<base href="" target="_blank">
<p>This is local HTML to my file system.</p>
<img src="images/myImage.gif" width="24" height="39" alt="Image">

Local File and Image From URL

You can also convert the base path programmatically, as the following example illustrates.

string filePath = "./myimage.jpg";
string tempHtml = "<html><body><img src=\"" + filePath + "\">" + "<img src=\"" + filePath + "\">" + "</body></html>";
Uri resolvePath = new Uri("http//mypath/");
Converter.Convert(tempHtml, "output.pdf", resolvePath);
Dim filePath As string = "./myimage.jpg"
Dim tempHtml As String = "<html><body><img src=""" & filePath & """>" & "<img src=""" & filePath & """>" & "</body></html>" 

Dim resolvePath As Uri = New Uri("http//mypath/")
Converter.Convert(tempHtml, "output.pdf", resolvePath)

Note that the example combines HTML obtained from a URL (the image file) with HTML from a local string. DynamicPDF HTML converter supports this mixed-conversion through the HTML base tag.

In this topic