Click or drag to resize
Pdf Library for .NET

HtmlToPdfConvertHtmlStringAsync(String, CancellationToken) Method

Asynchronously renders the specified HTML string and returns the result as a PDF document, stopping when the specified token is cancelled.

Namespace: SelectPdf.Universal
Assembly: SelectPdf.HtmlToPdf.Universal (in SelectPdf.HtmlToPdf.Universal.dll) Version: 26.4
Syntax
public Task<PdfDocument> ConvertHtmlStringAsync(
	string htmlString,
	CancellationToken cancellationToken
)

Parameters

htmlString  String
The HTML content to convert. Cannot be null.
cancellationToken  CancellationToken
A token that stops the conversion when it is cancelled.

Return Value

TaskPdfDocument
A task that completes with a PdfDocument containing the converted content. The caller is responsible for saving and closing the returned document.
Exceptions
ExceptionCondition
HtmlToPdfException The task faults with this exception when htmlString is null or when the conversion fails.
InvalidOperationException The task faults with this exception when this converter is already running a conversion.
OperationCanceledException The task is cancelled when cancellationToken is cancelled before the conversion completes.
Remarks
The conversion produces the same document as ConvertHtmlString(String), without holding a thread while the HTML renders. Cancelling the token stops the conversion; see ConvertUrlAsync(String, CancellationToken).
See Also