Skip to content

BaseConverter

BaseConverter is the abstract template-method base for all eight format converters (WordConverter, ExcelConverter, RtfConverter, TxtConverter, ImageConverter, TiffConverter, HtmlConverter, PdfConverter). It owns the conversion timing, status/result assembly, and exception capture that would otherwise be duplicated across every converter, and delegates only the format-specific work — the actual byte transformation and Syncfusion converter configuration — to each subclass. It is physically compiled into PdfAPI.SyncFusionCore but declares the namespace PdfAPI.Core.Convert, so consumers referencing only PdfAPI.Core cannot see it.

Purpose

  • Provide a single, shared implementation of Execute a single conversion (OP-SFC-002) so that timing, status stamping, and error handling are identical across every converter (BR-SFC-006, BR-SFC-007, BR-SFC-010).
  • Force each subclass to declare its own SourceConversionType and to implement the two format-specific extension points (ConvertItem, ConfigureConverter).

Context

  • Namespace: PdfAPI.Core.Convert
  • Assembly/package: PdfAPI.SyncFusionCore (Pdf.Local.Client NuGet package)

Public members

Member Signature Purpose
ConversionType abstract SourceConversionType ConversionType { get; } Identifies which source format this converter handles; set by each subclass to its own enum value (e.g. OfficeWordDoc, RTF, Tiff).
Convert PdfResult Convert(Stream stream, ConvertRequest request) Executes a full conversion: starts a stopwatch, calls ConfigureConverter then ConvertItem, builds and returns a PdfResult with Status, Elapsed, PdfProcessorType = Syncfusion, and the produced document; catches and captures any conversion exception rather than letting it propagate (BR-SFC-010).

Extension points (protected)

Member Signature Purpose
ConvertItem protected abstract byte[] ConvertItem(Stream stream, ConvertRequest request) Performs the format-specific byte transformation from the source stream to PDF bytes; implemented independently by each subclass. Not part of the public API — only reachable by subclasses.
ConfigureConverter protected abstract void ConfigureConverter(PdfOptions options) Declared as a hook for applying request-supplied options (such as PDF/A conformance) to the underlying Syncfusion converter before conversion runs. Not part of the public API — only reachable by subclasses. Currently a no-op in every in-scope converter subclass; none of the eight concrete implementations apply options to their underlying converter.

Behavioral notes

  • Convert always returns a PdfResult; a thrown exception from ConvertItem or ConfigureConverter is caught inside Convert and reported through the result rather than re-thrown to the caller (BR-SFC-010).
  • Elapsed on the returned PdfResult reflects the time spent inside Convert, including both ConfigureConverter and ConvertItem.
  • A successful result requires a non-null produced document; when ConvertItem returns null, the result is not reported as successful even though no exception was thrown (BR-SFC-007).

Constraints and usage notes

  • This type cannot be instantiated directly (abstract); it is always used through one of the eight concrete converter subclasses.
  • Consumers that reference only PdfAPI.Core (the contracts library) cannot see this type, since its declared namespace does not match its owning assembly.

Sources

  • PdfApi.SyncFusionCore\Convert\BaseConverter.cs