Click or drag to resize
Pdf Library for .NET

HtmlToPdfConvertHtmlString(String, String) Method

Renders the specified HTML string, resolving relative resources against the given base URL, and returns the result as a PDF document.

Namespace: SelectPdf.Universal
Assembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.5
Syntax
public PdfDocument ConvertHtmlString(
	string htmlString,
	string baseUrl
)

Parameters

htmlString  String
The HTML content to convert. Cannot be null.
baseUrl  String
The base URL used to resolve relative paths (images, style sheets, scripts) referenced by the HTML. May be null when the HTML has no relative resources. An http or https base URL is also the page's own address and origin: the HTML is served as the response for that URL, so web fonts, fetch requests, module scripts and cookies of the same site work as they do for a page converted by URL. A base element inside the HTML still wins.

Return Value

PdfDocument
A PdfDocument containing the converted content. The caller is responsible for saving and closing the returned document.
Exceptions
ExceptionCondition
HtmlToPdfException Thrown when htmlString is null or when the conversion fails.
Example
HtmlToPdf converter = new HtmlToPdf();
string html = "<img src='logo.png' /><p>Report</p>";
PdfDocument doc =
    converter.ConvertHtmlString(html, "https://www.example.com/");
doc.Save("report.pdf");
doc.Close();
See Also