Execute a single conversion (converter template)¶
This operation is the template-method core shared by all eight format converters: it owns stream disposal, timing, exception capture, and PdfResult assembly, while delegating the actual byte-level conversion to the subclass's ConvertItem hook.
| Field | Value |
|---|---|
| Operation ID | OP-SFC-002 |
| Trigger | Called by Convert a source document to PDF |
| Inputs | Source Stream, ConvertRequest |
| Outputs | PdfResult |
| Primary components | BaseConverter.Convert |
| Entry point | PdfApi.SyncFusionCore\Convert\BaseConverter.cs |
Steps¶
- Take ownership of the stream in a
usingblock, guaranteeing disposal on every path. - Call
ConfigureConverter(request.Options)— the per-format configuration hook. All eight concrete converters implement this as an empty method, so the hook is currently inert. - Create
new PdfResult(ConversionType, request)and stampPdfProcessorType = Syncfusion(BR-SFC-006). - Start a
Stopwatch. - Call the subclass
ConvertItem(stream, request)and wrap the returned bytes withDocument.Load(bytes, "pdf")(PdfAPI.Core). - The subclass hook is one of: Word document to PDF,
Excel workbook to PDF, RTF document to PDF, Plain text to PDF, Raster image to PDF, TIFF to multi-page PDF, HTML to PDF, or PDF pass-through or PDF/A upgrade, depending on which converter constructed this
BaseConverterinstance. - Set
Status = SucceededwhenDocument?.Fileis non-null, otherwiseFailed(BR-SFC-007); copyrequest.Optionsonto the result. - If PDF pass-through or PDF/A upgrade returns
null(no matching branch), this step marks the resultFailed. - Set
OutputFormattoPdfAwhenrequest.Options.IsPdfa, otherwisePdf(BR-SFC-008). - Parse
request.SourceSystemIdwithlong.TryParseintoresult.ImageId; a non-numeric or null value yields0(BR-SFC-009). - On any exception: record
ex.Messageinresult.Messageand setStatus = Failed. No rethrow, no logging (BR-SFC-010). - In
finally, stop the stopwatch and storesw.Elapsedon the result; return the result.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["Convert called with<br>stream and ConvertRequest"]) --> Dispose["Take ownership of stream<br>in using block"]
Dispose --> Configure["Call ConfigureConverter<br>currently a no-op hook"]
Configure --> Init["Create PdfResult,<br>stamp Syncfusion processor"]
Init --> StartTimer[Start Stopwatch]
StartTimer --> Try{"ConvertItem throws?"}
Try -->|No| WrapDoc["Wrap bytes with<br>Document.Load"]
WrapDoc --> DocNull{"Document.File<br>non-null?"}
DocNull -->|Yes| Succeed["Status = Succeeded"]
DocNull -->|No| Fail1["Status = Failed"]
Succeed --> SetFormat["Set OutputFormat<br>from Options.IsPdfa"]
Fail1 --> SetFormat
SetFormat --> ParseId["Parse SourceSystemId<br>to ImageId"]
Try -->|Yes| Catch["Catch exception:<br>Status = Failed,<br>Message = ex.Message"]
ParseId --> StopTimer["Stop Stopwatch,<br>store Elapsed"]
Catch --> StopTimer
StopTimer --> Result([Return PdfResult])
Failure and edge-case behavior¶
- Every exception raised by
ConvertItemis caught here; none of the eight format converters need their own exception handling to satisfy the caller's contract. - A converter that legitimately returns
nullbytes (only PDF pass-through or PDF/A upgrade, when neither branch applies) is treated the same as a failure, not as a distinct outcome.
Related documentation¶
Sources¶
PdfApi.SyncFusionCore\Convert\BaseConverter.cs