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
htmlstringThe markup to convert.
pagePageSetupThe page size, orientation and margins.
destinationStreamThe stream the result is written to.
ctCancellationTokenCancels the conversion and the write.
Returns
Exceptions
- ArgumentNullException
Any argument is null.
- ArgumentException
destinationis not writable.- OperationCanceledException
ctwas 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
htmlstringThe markup to convert.
pagePageSetupThe page size, orientation and margins.
ctCancellationTokenCancels the conversion.
Returns
Exceptions
- ArgumentNullException
htmlorpageis null.- OperationCanceledException
ctwas 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
htmlstringdestinationStreamctCancellationToken
Returns
Exceptions
- ArgumentNullException
htmlordestinationis null.- ArgumentException
destinationis not writable.- OperationCanceledException
ctwas 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
htmlstringctCancellationToken
Returns
Exceptions
- ArgumentNullException
htmlis null.- OperationCanceledException
ctwas cancelled.- DocumentConversionException
The HTML could not be converted.