Table of Contents

Interface IHtmlToPdfConverter

Namespace
DocToolkit.Extensions.DependencyInjection
Assembly
DocToolkit.Extensions.DependencyInjection.dll

Converts HTML straight to PDF by pivoting through DOCX. Registered by AddDocToolkit(IServiceCollection, Action<DocToolkitOptions>?); remote image download is controlled once, at registration, via AllowRemoteImageDownload, and bounded by RemoteImage.

public interface IHtmlToPdfConverter

Methods

ConvertAsync(string, PageSetup, Stream, CancellationToken)

As above, laid out on page rather than the A4 default.

Task ConvertAsync(string html, PageSetup page, Stream destination, CancellationToken ct = default)

Parameters

html string

The markup to convert.

page PageSetup

The page size, orientation and margins.

destination Stream

The stream the result is written to.

ct CancellationToken

Cancels the conversion and the write.

Returns

Task

Exceptions

ArgumentNullException

Any argument is null.

ArgumentException

destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted.

ConvertAsync(string, PageSetup, CancellationToken)

As above, laid out on page rather than the A4 default.

Task<byte[]> ConvertAsync(string html, PageSetup page, CancellationToken ct = default)

Parameters

html string

The markup to convert.

page PageSetup

The page size, orientation and margins.

ct CancellationToken

Cancels the conversion.

Returns

Task<byte[]>

Exceptions

ArgumentNullException

html or page is null.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted.

ConvertAsync(string, Stream, CancellationToken)

Converts html and writes the PDF to destination. destination is written, from its current position, and is not disposed, closed or sought.

The PDF is written straight through as the renderer produces it, so a failure part-way leaves whatever had already been produced on destination.

Task ConvertAsync(string html, Stream destination, CancellationToken ct = default)

Parameters

html string
destination Stream
ct CancellationToken

Returns

Task

Exceptions

ArgumentNullException

html or destination is null.

ArgumentException

destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted or written.

ConvertAsync(string, CancellationToken)

Converts html straight to PDF bytes.

Task<byte[]> ConvertAsync(string html, CancellationToken ct = default)

Parameters

html string
ct CancellationToken

Returns

Task<byte[]>

Exceptions

ArgumentNullException

html is null.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The HTML could not be converted.