Converter.ConvertHTML

Converter.ConvertHTML method

ConvertHTML(HtmlSource, SaveOptions, ICreateStreamProvider)

Converts source to the streams output creates, one per part.

public static ConversionResult ConvertHTML(HtmlSource source, SaveOptions options, ICreateStreamProvider output)
ParameterTypeDescription
sourceHtmlSourceThe HTML source.
optionsSaveOptionsPDF or image options.
outputICreateStreamProviderThe stream provider.

Return Value

ConversionResult: The conversion result.

See Also


ConvertHTML(HtmlSource, SaveOptions, Stream)

Converts source to output, left open.

public static ConversionResult ConvertHTML(HtmlSource source, SaveOptions options, Stream output)
ParameterTypeDescription
sourceHtmlSourceThe HTML source.
optionsSaveOptionsPDF or image options.
outputStreamA writable stream.

Return Value

ConversionResult: The conversion result.

See Also


ConvertHTML(HtmlSource, SaveOptions, string)

Converts source to the file outputPath.

public static ConversionResult ConvertHTML(HtmlSource source, SaveOptions options, string outputPath)
ParameterTypeDescription
sourceHtmlSourceThe HTML source.
optionsSaveOptionsPDF or image options.
outputPathstringThe output file; replaced only when the conversion succeeds.

Return Value

ConversionResult: The conversion result.

See Also


ConvertHTML(string, SaveOptions, string)

Converts the HTML file inputPath to the file outputPath.

public static ConversionResult ConvertHTML(string inputPath, SaveOptions options, string outputPath)
ParameterTypeDescription
inputPathstringThe input file; its directory is an allowed file root.
optionsSaveOptionsPDF or image options.
outputPathstringThe output file.

Return Value

ConversionResult: The conversion result.

See Also


ConvertHTML(Stream, string, SaveOptions, Stream)

Converts the HTML bytes of input to output; both stay open.

public static ConversionResult ConvertHTML(Stream input, string baseUri, SaveOptions options, Stream output)
ParameterTypeDescription
inputStreamThe input, read from its current position.
baseUristringAn absolute http(s) or file URI, or about:blank.
optionsSaveOptionsPDF or image options.
outputStreamA writable stream.

Return Value

ConversionResult: The conversion result.

See Also


ConvertHTML(Stream, string, SaveOptions, string)

Converts the HTML bytes of input to the file outputPath.

public static ConversionResult ConvertHTML(Stream input, string baseUri, SaveOptions options, string outputPath)
ParameterTypeDescription
inputStreamThe input, read from its current position and left open.
baseUristringAn absolute http(s) or file URI, or about:blank.
optionsSaveOptionsPDF or image options.
outputPathstringThe output file.

Return Value

ConversionResult: The conversion result.

See Also


ConvertHTML(string, string, SaveOptions, Stream)

Converts the markup html to output, left open.

public static ConversionResult ConvertHTML(string html, string baseUri, SaveOptions options, Stream output)
ParameterTypeDescription
htmlstringThe markup.
baseUristringAn absolute http(s) or file URI, or about:blank.
optionsSaveOptionsPDF or image options.
outputStreamA writable stream.

Return Value

ConversionResult: The conversion result.

See Also


ConvertHTML(string, string, SaveOptions, string)

Converts the markup html to the file outputPath.

public static ConversionResult ConvertHTML(string html, string baseUri, SaveOptions options, string outputPath)
ParameterTypeDescription
htmlstringThe markup.
baseUristringAn absolute http(s) or file URI, or about:blank.
optionsSaveOptionsPDF or image options.
outputPathstringThe output file.

Return Value

ConversionResult: The conversion result.

See Also


Examples

Convert a local invoice with the familiar Aspose call.

var result = Converter.ConvertHTML("invoice.html", new PdfSaveOptions(), "invoice.pdf");
Console.WriteLine(result.PageCount);

Convert stream-to-stream without accidental ownership transfer.

using var input = File.OpenRead("report.html");
using var output = File.Create("report.pdf");
Converter.ConvertHTML(input, "https://assets.example/", new PdfSaveOptions(), output);

Produce one print-resolution PNG per page with explicit stream completion.

var images = new ImageSaveOptions {
    Mode = ImageMode.PrintPages, HorizontalResolution = 300, VerticalResolution = 300,
};
images.Css.MediaType = MediaType.Print;
Converter.ConvertHTML(HtmlSource.FromFile("report.html"), images, new PageFiles());

private sealed class PageFiles : ICreateStreamProvider
{
    public Stream GetStream(OutputPart part) => File.Create($"page-{part.Index + 1}.png");

    public void Complete(OutputPart part, Stream stream, OutputOutcome outcome)
    {
        stream.Dispose();
        if (outcome != OutputOutcome.Completed) File.Delete($"page-{part.Index + 1}.png");
    }
}