Skip to content

HTML to PDF

Converts an HTML document stream to PDF bytes using the Syncfusion HtmlToPdfConverter configured with the Internet Explorer rendering engine.

Field Value
Operation ID OP-SFC-010
Trigger Called by Execute a single conversion (converter template) via HtmlConverter.ConvertItem, dispatched from Convert a source document to PDF for html
Inputs Source Stream, ConvertRequest
Outputs PDF byte[]
Primary components HtmlConverter.ConvertItem
Entry point PdfApi.SyncFusionCore\Convert\HtmlConverter.cs

Steps

  1. Read the entire stream as a string using a default-encoding StreamReader.
  2. Create a Syncfusion.HtmlConverter.HtmlToPdfConverter with IEConverterSettings (Internet Explorer rendering engine) (BR-SFC-022).
  3. Set settings.IsPDFA1B = (request.Format == PdfFormat.PdfA) (BR-SFC-011).
  4. This branch reads request.Format, not request.Options.IsPdfa as the other converters do — the two are equivalent because ConvertRequest.Format proxies Options.OutputFormat.
  5. Call converter.Convert(html, "") with an empty base URL, save to a MemoryStream, and return the bytes (BR-SFC-023).

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["ConvertItem called<br>with stream, request"]) --> Read[Read stream as string]
    Read --> Create["Create HtmlToPdfConverter<br>with IEConverterSettings"]
    Create --> SetPdfa["Set IsPDFA1B from<br>request.Format"]
    SetPdfa --> Convert["converter.Convert html,<br>empty base URL"]
    Convert --> Save[Save to MemoryStream]
    Save --> Return([Return PDF bytes])

Failure and edge-case behavior

  • Any Syncfusion conversion failure surfaces as an exception, which is caught by Execute a single conversion (converter template) and turned into a failed PdfResult rather than propagated here.
  • Relative resource references in the source HTML (images, stylesheets) do not resolve because the base URL is empty.
  • Untrusted HTML is rendered in-process by a legacy browser engine with no sanitization or resource-access restriction configured.*

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

Sources

  • PdfApi.SyncFusionCore\Convert\HtmlConverter.cs