 |
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.UniversalAssembly: SelectPdf.HtmlToPdf.Universal (in SelectPdf.HtmlToPdf.Universal.dll) Version: 26.4
Syntaxpublic PdfDocument ConvertHtmlString(
string htmlString,
string baseUrl
)
Public Function ConvertHtmlString (
htmlString As String,
baseUrl As String
) As PdfDocument
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.
Return Value
PdfDocument
A
PdfDocument containing the converted content. The caller is responsible
for saving and closing the returned document.
Exceptions| Exception | Condition |
|---|
| HtmlToPdfException |
Thrown when htmlString is null or when the conversion fails.
|
ExampleHtmlToPdf 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();Dim converter As New HtmlToPdf()
Dim html As String =
Dim doc As PdfDocument =
converter.ConvertHtmlString(html, "https://www.example.com/")
doc.Save("report.pdf")
doc.Close()
See Also